diff --git a/.gitignore b/.gitignore index 5502819..90cbdbb 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,5 @@ gradle-app.setting # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties +# Generated data files +output/ diff --git a/1.14.4/.gitignore b/1.14.4/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.14.4/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.14.4/build.gradle.kts b/1.14.4/build.gradle.kts new file mode 100644 index 0000000..80dd2d6 --- /dev/null +++ b/1.14.4/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.14.4") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..9765fec --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,18 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..ee06df4 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,27 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return Registry.BIOME.keySet().stream().map(ResourceLocation::getPath).iterator(); + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..1bc6358 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,144 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + private static final AABB FULL_CUBE = AABB.of(BoundingBox.getUnknownBox()); + + public BlockRegistryDumper(File file) { + super(file); + } + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = Registry.BLOCK.get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getElement(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + map.put("translucent", bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", !m.isAlwaysDestroyable()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock bep && + bep.newBlockEntity(EmptyBlockGetter.INSTANCE) instanceof Clearable); + return map; + } + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..85687b7 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,42 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return BlockTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign" + ); + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..2189f10 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,136 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.EntityTypeTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagCollection; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getWorldVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(TagCollection provider, Registry registry) { + Map> tagCollector = new TreeMap<>(); + + provider.getAllTags().forEach((key, value) -> + tagCollector.put(key.toString(), value.getValues().stream() + .map(entry -> checkNotNull(registry.getKey(entry))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : Registry.BLOCK.keySet()) { + Map bl = new TreeMap<>(); + Block block = Registry.BLOCK.get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().getName())).forEach(e -> bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase())); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = Registry.ITEM.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = Registry.ENTITY_TYPE.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = Registry.BIOME.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // BlockTags + Map> blockTags = getTags(BlockTags.getAllTags(), Registry.BLOCK); + + // ItemTags + Map> itemTags = getTags(ItemTags.getAllTags(), Registry.ITEM); + + // EntityTags + Map> entityTags = getTags(EntityTypeTags.getAllTags(), Registry.ENTITY_TYPE); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..51d7315 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,33 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.EntityTypeTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return Registry.ENTITY_TYPE.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return EntityTypeTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..890b78a --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,59 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = Registry.ITEM.get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..c6be545 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,44 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return ItemTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign" + ); + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..48264e0 --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,42 @@ +package org.enginehub.util.minecraft.util; + +import net.minecraft.SharedConstants; +import net.minecraft.data.Main; +import net.minecraft.data.tags.BlockTagsProvider; +import net.minecraft.data.tags.EntityTypeTagsProvider; +import net.minecraft.data.tags.ItemTagsProvider; +import net.minecraft.data.tags.TagsProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.Bootstrap; +import net.minecraft.tags.*; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.io.IOException; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.getCurrentVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + + BlockTags.reset(setupTags(new BlockTagsProvider(null))); + ItemTags.reset(setupTags(new ItemTagsProvider(null))); + EntityTypeTags.reset(setupTags(new EntityTypeTagsProvider(null))); + } + + private static TagCollection setupTags(TagsProvider tagsProvider) { + Map, Tag.Builder> builders = (Map, Tag.Builder>) ReflectionUtil.getField(tagsProvider, TagsProvider.class, "builders"); + builders.clear(); + ReflectionUtil.invokeMethod(tagsProvider, tagsProvider.getClass(), "addTags", null, null); + TagCollection tagCollection = new TagCollection<>(resourceLocation -> Optional.empty(), "", false, "generated"); + Map> map = builders.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().getId(), Map.Entry::getValue)); + tagCollection.load(map); + return tagCollection; + } +} diff --git a/1.14.4/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java b/1.14.4/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java new file mode 100644 index 0000000..e5950bf --- /dev/null +++ b/1.14.4/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java @@ -0,0 +1,28 @@ +package org.enginehub.util.minecraft.util; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class ReflectionUtil { + + public static Object getField(Object obj, Class clazz, String name) { + try { + Field f = clazz.getDeclaredField(name); + f.setAccessible(true); + return f.get(obj); + } catch (IllegalAccessException | NoSuchFieldException ignored) { + } + return null; + } + + public static Object invokeMethod(Object obj, Class clazz, String name, Class[] paramClasses, Object[] params) { + try { + Method m = clazz.getDeclaredMethod(name, paramClasses); + m.setAccessible(true); + return m.invoke(obj, params); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + } + return null; + } +} \ No newline at end of file diff --git a/1.15.2/.gitignore b/1.15.2/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.15.2/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.15.2/build.gradle.kts b/1.15.2/build.gradle.kts new file mode 100644 index 0000000..aa4eed4 --- /dev/null +++ b/1.15.2/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.15.2") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..9765fec --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,18 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..ee06df4 --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,27 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return Registry.BIOME.keySet().stream().map(ResourceLocation::getPath).iterator(); + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..1bc6358 --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,144 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + private static final AABB FULL_CUBE = AABB.of(BoundingBox.getUnknownBox()); + + public BlockRegistryDumper(File file) { + super(file); + } + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = Registry.BLOCK.get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getElement(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + map.put("translucent", bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", !m.isAlwaysDestroyable()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock bep && + bep.newBlockEntity(EmptyBlockGetter.INSTANCE) instanceof Clearable); + return map; + } + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..b7835bb --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,49 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return BlockTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "dirt_like" + ); + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..330545f --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,133 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.*; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getWorldVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(TagCollection provider, Registry registry) { + Map> tagCollector = new TreeMap<>(); + + provider.getAllTags().forEach((key, value) -> + tagCollector.put(key.toString(), value.getValues().stream() + .map(entry -> checkNotNull(registry.getKey(entry))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : Registry.BLOCK.keySet()) { + Map bl = new TreeMap<>(); + Block block = Registry.BLOCK.get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().getName())).forEach(e -> bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase())); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = Registry.ITEM.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = Registry.ENTITY_TYPE.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = Registry.BIOME.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // BlockTags + Map> blockTags = getTags(BlockTags.getAllTags(), Registry.BLOCK); + + // ItemTags + Map> itemTags = getTags(ItemTags.getAllTags(), Registry.ITEM); + + // EntityTags + Map> entityTags = getTags(EntityTypeTags.getAllTags(), Registry.ENTITY_TYPE); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..51d7315 --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,33 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.EntityTypeTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return Registry.ENTITY_TYPE.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return EntityTypeTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..890b78a --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,59 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = Registry.ITEM.get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..c6be545 --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,44 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.ItemTags; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return ItemTags.getAllTags().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign" + ); + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..47a5d93 --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,40 @@ +package org.enginehub.util.minecraft.util; + +import net.minecraft.SharedConstants; +import net.minecraft.data.tags.BlockTagsProvider; +import net.minecraft.data.tags.EntityTypeTagsProvider; +import net.minecraft.data.tags.ItemTagsProvider; +import net.minecraft.data.tags.TagsProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.Bootstrap; +import net.minecraft.tags.*; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.getCurrentVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + + BlockTags.reset(setupTags(new BlockTagsProvider(null))); + ItemTags.reset(setupTags(new ItemTagsProvider(null))); + EntityTypeTags.reset(setupTags(new EntityTypeTagsProvider(null))); + } + + private static TagCollection setupTags(TagsProvider tagsProvider) { + Map, Tag.Builder> builders = (Map, Tag.Builder>) ReflectionUtil.getField(tagsProvider, TagsProvider.class, "builders"); + builders.clear(); + ReflectionUtil.invokeMethod(tagsProvider, tagsProvider.getClass(), "addTags", null, null); + TagCollection tagCollection = new TagCollection<>(resourceLocation -> Optional.empty(), "", false, "generated"); + Map> map = builders.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().getId(), Map.Entry::getValue)); + tagCollection.load(map); + return tagCollection; + } +} diff --git a/1.15.2/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java b/1.15.2/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java new file mode 100644 index 0000000..e5950bf --- /dev/null +++ b/1.15.2/src/main/java/org/enginehub/util/minecraft/util/ReflectionUtil.java @@ -0,0 +1,28 @@ +package org.enginehub.util.minecraft.util; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class ReflectionUtil { + + public static Object getField(Object obj, Class clazz, String name) { + try { + Field f = clazz.getDeclaredField(name); + f.setAccessible(true); + return f.get(obj); + } catch (IllegalAccessException | NoSuchFieldException ignored) { + } + return null; + } + + public static Object invokeMethod(Object obj, Class clazz, String name, Class[] paramClasses, Object[] params) { + try { + Method m = clazz.getDeclaredMethod(name, paramClasses); + m.setAccessible(true); + return m.invoke(obj, params); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + } + return null; + } +} \ No newline at end of file diff --git a/1.16.5/.gitignore b/1.16.5/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.16.5/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.16.5/build.gradle.kts b/1.16.5/build.gradle.kts new file mode 100644 index 0000000..a2eb572 --- /dev/null +++ b/1.16.5/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.16.5") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..c88321d --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,20 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + GameSetupUtils.getServerResources(); + GameSetupUtils.getServerRegistry(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..cc327a5 --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,37 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistry; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +// TODO Find out how to get the Biome tags for dumping +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "nether" + ); + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..5fc2568 --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,142 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public BlockRegistryDumper(File file) { + super(file); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = Registry.BLOCK.get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getOrDefault(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(null, null)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", bs.requiresCorrectToolForDrops()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock && ((EntityBlock) b).newBlockEntity(EmptyBlockGetter.INSTANCE) instanceof Clearable); + return map; + } + + // method_29968 -> adds one to get max + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..3588f80 --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,49 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getBlocks().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "dirt_like" + ); + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..b761c6f --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,139 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.*; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getWorldVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(TagCollection provider, Registry registry) { + Map> tagCollector = new TreeMap<>(); + + provider.getAllTags().forEach((key, value) -> + tagCollector.put(key.toString(), value.getValues().stream() + .map(entry -> checkNotNull(registry.getKey(entry))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : Registry.BLOCK.keySet()) { + Map bl = new TreeMap<>(); + Block block = Registry.BLOCK.get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream() + .sorted(Comparator.comparing(e -> e.getKey().getName())) + .forEach(e -> + bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) + ); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = Registry.ITEM.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = Registry.ENTITY_TYPE.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + TagContainer tagManager = getServerResources().getTags(); + // BlockTags + Map> blockTags = getTags(tagManager.getBlocks(), Registry.BLOCK); + + // ItemTags + Map> itemTags = getTags(tagManager.getItems(), Registry.ITEM); + + // EntityTags + Map> entityTags = getTags(tagManager.getEntityTypes(), Registry.ENTITY_TYPE); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..bf8511c --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,41 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return Registry.ENTITY_TYPE.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getEntityTypes().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "zombie_pigman" + ); + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..890b78a --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,59 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = Registry.ITEM.get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..588d830 --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,52 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getItems().getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign", + "zombie_pigman_spawn_egg" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "furnace_materials" + ); + } +} diff --git a/1.16.5/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.16.5/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..4527d15 --- /dev/null +++ b/1.16.5/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,79 @@ +package org.enginehub.util.minecraft.util; + +import com.google.common.util.concurrent.Futures; +import net.minecraft.SharedConstants; +import net.minecraft.commands.Commands; +import net.minecraft.core.RegistryAccess; +import net.minecraft.server.Bootstrap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerResources; +import net.minecraft.server.packs.repository.Pack; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.world.level.DataPackConfig; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.getCurrentVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + } + + private static final Lock lock = new ReentrantLock(); + private static ServerResources SERVER_RESOURCES; + private static RegistryAccess SERVER_REGISTRY; + + public static ServerResources getServerResources() { + setupGame(); + lock.lock(); + try { + ServerResources localResources = SERVER_RESOURCES; + if (localResources != null) { + return localResources; + } + PackRepository resourcePackManager = new PackRepository( + Pack::new, + new ServerPacksSource() + ); + MinecraftServer.configurePackRepository(resourcePackManager, DataPackConfig.DEFAULT, true); + CompletableFuture completableFuture = ServerResources.loadResources( + resourcePackManager.openAllSelected(), + Commands.CommandSelection.DEDICATED, + // permission level doesn't matter + 0, + ForkJoinPool.commonPool(), + Runnable::run + ); + ServerResources manager = Futures.getUnchecked(completableFuture); + manager.updateGlobals(); + SERVER_RESOURCES = manager; + return manager; + } finally { + lock.unlock(); + } + } + + public static RegistryAccess getServerRegistry() { + lock.lock(); + try { + RegistryAccess localResources = SERVER_REGISTRY; + if (localResources != null) { + return localResources; + } + RegistryAccess manager = RegistryAccess.builtin(); + SERVER_REGISTRY = manager; + return manager; + } finally { + lock.unlock(); + } + } +} diff --git a/1.17.1/.gitignore b/1.17.1/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.17.1/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.17.1/build.gradle.kts b/1.17.1/build.gradle.kts new file mode 100644 index 0000000..13fea77 --- /dev/null +++ b/1.17.1/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.17.1") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..c88321d --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,20 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + GameSetupUtils.getServerResources(); + GameSetupUtils.getServerRegistry(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..ec1ff0a --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,40 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.*; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getOrEmpty(Registry.BIOME_REGISTRY).getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "nether" + ); + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..b3b523c --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,143 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); + + public BlockRegistryDumper(File file) { + super(file); + } + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = Registry.BLOCK.get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getOrDefault(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + map.put("translucent", bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", bs.requiresCorrectToolForDrops()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock bep && + bep.newBlockEntity(BlockPos.ZERO, bs) instanceof Clearable); + return map; + } + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..3f5b3bf --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,50 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "dirt_like" + ); + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..aa68471 --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,139 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.*; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getWorldVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(TagCollection provider, Registry registry) { + Map> tagCollector = new TreeMap<>(); + + provider.getAllTags().forEach((key, value) -> + tagCollector.put(key.toString(), value.getValues().stream() + .map(entry -> checkNotNull(registry.getKey(entry))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : Registry.BLOCK.keySet()) { + Map bl = new TreeMap<>(); + Block block = Registry.BLOCK.get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream() + .sorted(Comparator.comparing(e -> e.getKey().getName())) + .forEach(e -> + bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) + ); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = Registry.ITEM.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = Registry.ENTITY_TYPE.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + TagContainer tagManager = getServerResources().getTags(); + // BlockTags + Map> blockTags = getTags(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY), Registry.BLOCK); + + // ItemTags + Map> itemTags = getTags(tagManager.getOrEmpty(Registry.ITEM_REGISTRY), Registry.ITEM); + + // EntityTags + Map> entityTags = getTags(tagManager.getOrEmpty(Registry.ENTITY_TYPE_REGISTRY), Registry.ENTITY_TYPE); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..9008d17 --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,41 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return Registry.ENTITY_TYPE.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "zombie_pigman" + ); + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..890b78a --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,59 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = Registry.ITEM.get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..d46314c --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,53 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerResources; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerResources().getTags().getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign", + "zombie_pigman_spawn_egg", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "furnace_materials" + ); + } +} diff --git a/1.17.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.17.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..d555307 --- /dev/null +++ b/1.17.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,81 @@ +package org.enginehub.util.minecraft.util; + +import com.google.common.util.concurrent.Futures; +import net.minecraft.SharedConstants; +import net.minecraft.commands.Commands; +import net.minecraft.core.RegistryAccess; +import net.minecraft.server.Bootstrap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.world.level.DataPackConfig; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + } + + private static final Lock lock = new ReentrantLock(); + private static ServerResources SERVER_RESOURCES; + private static RegistryAccess SERVER_REGISTRY; + + public static ServerResources getServerResources() { + setupGame(); + lock.lock(); + try { + ServerResources localResources = SERVER_RESOURCES; + if (localResources != null) { + return localResources; + } + PackRepository resourcePackManager = new PackRepository( + PackType.SERVER_DATA, + new ServerPacksSource() + ); + MinecraftServer.configurePackRepository(resourcePackManager, DataPackConfig.DEFAULT, true); + RegistryAccess.RegistryHolder impl = (RegistryAccess.RegistryHolder) getServerRegistry(); + CompletableFuture completableFuture = ServerResources.loadResources( + resourcePackManager.openAllSelected(), + impl, + Commands.CommandSelection.DEDICATED, + // permission level doesn't matter + 0, + ForkJoinPool.commonPool(), + Runnable::run + ); + ServerResources manager = Futures.getUnchecked(completableFuture); + manager.updateGlobals(); + SERVER_RESOURCES = manager; + return manager; + } finally { + lock.unlock(); + } + } + + public static RegistryAccess getServerRegistry() { + lock.lock(); + try { + RegistryAccess localResources = SERVER_REGISTRY; + if (localResources != null) { + return localResources; + } + RegistryAccess manager = RegistryAccess.builtin(); + SERVER_REGISTRY = manager; + return manager; + } finally { + lock.unlock(); + } + } +} diff --git a/1.18.2/.gitignore b/1.18.2/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.18.2/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.18.2/build.gradle.kts b/1.18.2/build.gradle.kts new file mode 100644 index 0000000..4276c40 --- /dev/null +++ b/1.18.2/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.18.2") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..c88321d --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,20 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + GameSetupUtils.getServerResources(); + GameSetupUtils.getServerRegistry(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..e37f1e9 --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,78 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistry; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "nether", + "tall_birch_forest", + "giant_tree_taiga", + "giant_spruce_taiga", + "snowy_tundra", + "jungle_edge", + "stone_shore", + "mountains", + "wooded_mountains", + "gravelly_mountains", + "shattered_savanna", + "wooded_badlands_plateau", + "badlands_plateau", + "bamboo_jungle_hills", + "birch_forest_hills", + "dark_forest_hills", + "deep_warm_ocean", + "desert_hills", + "desert_lakes", + "giant_spruce_taiga_hills", + "giant_tree_taiga_hills", + "modified_gravelly_hills", + "jungle_hills", + "modified_badlands_plateau", + "modified_jungle", + "modified_jungle_edge", + "modified_wooded_badlands_plateau", + "mountain_edge", + "mushroom_field_shore", + "shattered_savanna_plateau", + "snowy_mountains", + "snowy_taiga_hills", + "snowy_taiga_mountains", + "swamp_hills", + "taiga_hills", + "taiga_mountains", + "tall_birch_hills", + "wooded_hills" + ); + } +} diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..c9eff23 --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,142 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); + + public BlockRegistryDumper(File file) { + super(file); + } + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = Registry.BLOCK.get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getOrDefault(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + map.put("translucent", bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", bs.requiresCorrectToolForDrops()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock bep && bep.newBlockEntity(BlockPos.ZERO, bs) instanceof Clearable); + return map; + } + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java similarity index 54% rename from src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java rename to 1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java index e5921c3..de2ac44 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -3,7 +3,6 @@ import com.google.auto.service.AutoService; import com.google.common.collect.Iterators; import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import java.util.Iterator; @@ -19,28 +18,32 @@ public static void main(String[] args) { } public BlockTypesDumper() { - super( - Registries.BLOCK, - "com.sk89q.worldedit.world.block", "Block" - ); + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return Registry.BLOCK.keySet().stream().map(ResourceLocation::getPath).iterator(); } @Override - protected Iterator getDeprecatedIds() { + protected Iterator getTags() { + return Registry.BLOCK.getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { return Iterators.forArray( - new ResourceLocation("sign"), - new ResourceLocation("wall_sign"), - new ResourceLocation("grass_path") + "sign", + "wall_sign", + "grass_path" ); } @Override - protected Iterator getDeprecatedTags() { + protected Iterator getDeprecatedTags() { return Iterators.forArray( - new ResourceLocation("dirt_like"), - new ResourceLocation("carpets"), - new ResourceLocation("lava_pool_stone_replaceables") + "dirt_like" ); } } - diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..5e1065c --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,137 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistry; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getDataVersion().getVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(Registry registry) { + Map> tagCollector = new TreeMap<>(); + + registry.getTags().forEach(tagPair -> + tagCollector.put(tagPair.getFirst().location().toString(), tagPair.getSecond().stream() + .map(entry -> checkNotNull(registry.getResourceKey(entry.value()))) + .map(Optional::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : Registry.BLOCK.keySet()) { + Map bl = new TreeMap<>(); + Block block = Registry.BLOCK.get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream() + .sorted(Comparator.comparing(e -> e.getKey().getName())) + .forEach(e -> + bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) + ); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = Registry.ITEM.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = Registry.ENTITY_TYPE.keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = getServerRegistry().registryOrThrow(Registry.BIOME_REGISTRY).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // BlockTags + Map> blockTags = getTags(Registry.BLOCK); + + // ItemTags + Map> itemTags = getTags(Registry.ITEM); + + // EntityTags + Map> entityTags = getTags(Registry.ENTITY_TYPE); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java similarity index 57% rename from src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java rename to 1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java index 9d1a1f7..f09f88a 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -3,7 +3,6 @@ import com.google.auto.service.AutoService; import com.google.common.collect.Iterators; import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import java.util.Iterator; @@ -19,16 +18,23 @@ public static void main(String[] args) { } public EntityTypesDumper() { - super( - Registries.ENTITY_TYPE, - "com.sk89q.worldedit.world.entity", "Entity" - ); + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return Registry.ENTITY_TYPE.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return Registry.ENTITY_TYPE.getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); } @Override - protected Iterator getDeprecatedIds() { + protected Iterator getDeprecatedIds() { return Iterators.forArray( - new ResourceLocation("zombie_pigman") + "zombie_pigman" ); } } diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..890b78a --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,59 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = Registry.ITEM.get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..d0cc2df --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,52 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return Registry.ITEM.keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return Registry.ITEM.getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign", + "zombie_pigman_spawn_egg", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "furnace_materials" + ); + } +} diff --git a/1.18.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.18.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..fbdca23 --- /dev/null +++ b/1.18.2/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,79 @@ +package org.enginehub.util.minecraft.util; + +import com.google.common.util.concurrent.Futures; +import net.minecraft.SharedConstants; +import net.minecraft.commands.Commands; +import net.minecraft.core.RegistryAccess; +import net.minecraft.server.Bootstrap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ReloadableServerResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.server.packs.resources.MultiPackResourceManager; +import net.minecraft.world.level.DataPackConfig; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + } + + private static final Lock lock = new ReentrantLock(); + private static ReloadableServerResources SERVER_RESOURCES; + private static RegistryAccess SERVER_REGISTRY; + + public static ReloadableServerResources getServerResources() { + setupGame(); + lock.lock(); + try { + ReloadableServerResources localResources = SERVER_RESOURCES; + if (localResources != null) { + return localResources; + } + PackRepository resourcePackManager = new PackRepository( + PackType.SERVER_DATA, + new ServerPacksSource() + ); + MinecraftServer.configurePackRepository(resourcePackManager, DataPackConfig.DEFAULT, true); + RegistryAccess.Frozen immutable = RegistryAccess.BUILTIN.get(); + MultiPackResourceManager lifecycledResourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, resourcePackManager.openAllSelected()); + CompletableFuture completableFuture = (ReloadableServerResources.loadResources(lifecycledResourceManager, immutable, Commands.CommandSelection.DEDICATED, 0, ForkJoinPool.commonPool(), Runnable::run).whenComplete((dataPackContents, throwable) -> { + if (throwable != null) { + lifecycledResourceManager.close(); + } + })); + ReloadableServerResources manager = Futures.getUnchecked(completableFuture); + manager.updateRegistryTags(immutable); + SERVER_RESOURCES = manager; + return manager; + } finally { + lock.unlock(); + } + } + + public static RegistryAccess getServerRegistry() { + lock.lock(); + try { + RegistryAccess localResources = SERVER_REGISTRY; + if (localResources != null) { + return localResources; + } + RegistryAccess manager = RegistryAccess.BUILTIN.get(); + SERVER_REGISTRY = manager; + return manager; + } finally { + lock.unlock(); + } + } +} diff --git a/1.19.4/.gitignore b/1.19.4/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.19.4/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.19.4/build.gradle.kts b/1.19.4/build.gradle.kts new file mode 100644 index 0000000..fe4a868 --- /dev/null +++ b/1.19.4/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.19.4") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/RunAll.java similarity index 80% rename from src/main/java/org/enginehub/util/minecraft/RunAll.java rename to 1.19.4/src/main/java/org/enginehub/util/minecraft/RunAll.java index 7678f65..1be5b9d 100644 --- a/src/main/java/org/enginehub/util/minecraft/RunAll.java +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -6,13 +6,14 @@ import java.util.ServiceLoader; public class RunAll { + public static void main(String[] args) { GameSetupUtils.setupGame(); GameSetupUtils.getServerRegistries(); for (Dumper dumper : ServiceLoader.load(Dumper.class)) { - System.err.println("Running dumper: " + dumper.getClass().getCanonicalName()); + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); dumper.run(); - System.err.println("Finished!"); + System.out.println("Finished!"); } } } diff --git a/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..3093723 --- /dev/null +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,78 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.BIOME).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.BIOME).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "nether", + "tall_birch_forest", + "giant_tree_taiga", + "giant_spruce_taiga", + "snowy_tundra", + "jungle_edge", + "stone_shore", + "mountains", + "wooded_mountains", + "gravelly_mountains", + "shattered_savanna", + "wooded_badlands_plateau", + "badlands_plateau", + "bamboo_jungle_hills", + "birch_forest_hills", + "dark_forest_hills", + "deep_warm_ocean", + "desert_hills", + "desert_lakes", + "giant_spruce_taiga_hills", + "giant_tree_taiga_hills", + "modified_gravelly_hills", + "jungle_hills", + "modified_badlands_plateau", + "modified_jungle", + "modified_jungle_edge", + "modified_wooded_badlands_plateau", + "mountain_edge", + "mushroom_field_shore", + "shattered_savanna_plateau", + "snowy_mountains", + "snowy_taiga_hills", + "snowy_taiga_mountains", + "swamp_hills", + "taiga_hills", + "taiga_mountains", + "tall_birch_hills", + "wooded_hills" + ); + } +} diff --git a/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java new file mode 100644 index 0000000..9216afb --- /dev/null +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -0,0 +1,143 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Lists; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Vec3i; +import net.minecraft.core.registries.Registries; +import net.minecraft.locale.Language; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Clearable; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class BlockRegistryDumper extends RegistryDumper { + + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); + + public BlockRegistryDumper(File file) { + super(file); + } + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @Override + public void registerAdapters(GsonBuilder builder) { + super.registerAdapters(builder); + + builder.registerTypeAdapter(Vec3i.class, new Vec3iAdapter()); + builder.registerTypeAdapter(Vec3.class, new Vec3dAdapter()); + } + + @Override + public Collection getIds() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Block block = getServerRegistries().registryOrThrow(Registries.BLOCK).get(new ResourceLocation(resourceLocation)); + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("localizedName", Language.getInstance().getOrDefault(block.getDescriptionId())); + map.put("material", getMaterial(block)); + return Lists.newArrayList(map); + } + + private Map getMaterial(Block b) { + BlockState bs = b.defaultBlockState(); + Map map = new TreeMap<>(); + map.put("powerSource", bs.isSignalSource()); + map.put("lightValue", bs.getLightEmission()); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + map.put("resistance", b.getExplosionResistance()); + map.put("ticksRandomly", b.isRandomlyTicking(bs)); + VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); + map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); + map.put("slipperiness", b.getFriction()); + // map.put("translucent", bs.isTranslucent(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + Material m = bs.getMaterial(); + map.put("liquid", m.isLiquid()); + map.put("solid", m.isSolid()); + map.put("movementBlocker", m.blocksMotion()); + map.put("burnable", m.isFlammable()); + map.put("opaque", m.isSolidBlocking()); + map.put("replacedDuringPlacement", m.isReplaceable()); + map.put("toolRequired", bs.requiresCorrectToolForDrops()); + map.put("fragileWhenPushed", m.getPushReaction() == PushReaction.DESTROY); + map.put("unpushable", m.getPushReaction() == PushReaction.BLOCK); + map.put("mapColor", rgb(m.getColor().col)); + map.put("hasContainer", b instanceof EntityBlock bep && bep.newBlockEntity(BlockPos.ZERO, bs) instanceof Clearable); + return map; + } + + private boolean isFullCube(AABB aabb) { + return aabb.equals(FULL_CUBE); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + + public static class Vec3iAdapter extends TypeAdapter { + @Override + public Vec3i read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3i vec) throws IOException { + out.beginArray(); + out.value(vec.getX()); + out.value(vec.getY()); + out.value(vec.getZ()); + out.endArray(); + } + } + + public static class Vec3dAdapter extends TypeAdapter { + @Override + public Vec3 read(final JsonReader in) { + throw new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Vec3 vec) throws IOException { + out.beginArray(); + out.value(vec.x()); + out.value(vec.y()); + out.value(vec.z()); + out.endArray(); + } + } +} diff --git a/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..8696ff6 --- /dev/null +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,52 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "dirt_like", + "carpets", + "lava_pool_stone_replaceables" + ); + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java similarity index 80% rename from src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java rename to 1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java index 69ecdad..806d11e 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -9,27 +9,19 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.block.state.properties.DirectionProperty; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.level.block.state.properties.*; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; -public class DataVersionDumper implements Dumper { +public class DataVersionDumper extends AbstractDumper { public static void main(String[] args) { setupGame(); @@ -40,7 +32,7 @@ public static void main(String[] args) { public static class Default implements Dumper { @Override public void run() { - File file = new File("output/" + SharedConstants.getCurrentVersion().getDataVersion().getVersion() + ".json"); + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getDataVersion().getVersion() + ".json"); new DataVersionDumper(file).run(); } } @@ -56,12 +48,11 @@ private Map> getTags(Registry registry) { Map> tagCollector = new TreeMap<>(); registry.getTags().forEach(tagPair -> - tagCollector.put(tagPair.getFirst().location().toString(), tagPair.getSecond().stream() - .map(entry -> checkNotNull(registry.getKey(entry.value()))) - .map(ResourceLocation::toString) - .sorted() - .collect(Collectors.toList())) - ); + tagCollector.put(tagPair.getFirst().location().toString(), tagPair.getSecond().stream() + .map(entry -> checkNotNull(registry.getKey(entry.value()))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); return tagCollector; } @@ -101,10 +92,10 @@ public void run() { if (!block.defaultBlockState().getValues().isEmpty()) { List bits = new ArrayList<>(); block.defaultBlockState().getValues().entrySet().stream() - .sorted(Comparator.comparing(e -> e.getKey().getName())) - .forEach(e -> - bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) - ); + .sorted(Comparator.comparing(e -> e.getKey().getName())) + .forEach(e -> + bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) + ); defaultState.append("[").append(String.join(",", bits)).append("]"); } bl.put("defaultstate", defaultState.toString()); @@ -145,4 +136,3 @@ public void run() { } } } - diff --git a/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..80d3822 --- /dev/null +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,41 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "zombie_pigman" + ); + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java similarity index 66% rename from src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java rename to 1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java index abc8d7b..7db57ab 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -1,19 +1,14 @@ package org.enginehub.util.minecraft.dumper; import com.google.auto.service.AutoService; -import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; -import org.enginehub.util.minecraft.util.GameSetupUtils; import java.io.File; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; public class ItemRegistryDumper extends RegistryDumper { @@ -27,7 +22,7 @@ public static void main(String[] args) { public static class Default implements Dumper { @Override public void run() { - new ItemRegistryDumper(new File("output/items.json")).run(); + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); } } @@ -36,8 +31,8 @@ public ItemRegistryDumper(File file) { } @Override - public Registry getRegistry() { - return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.ITEM); + public Collection getIds() { + return getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().map(ResourceLocation::toString).toList(); } @Override @@ -45,15 +40,17 @@ public Comparator> getComparator() { return Comparator.comparing(map -> (String) map.get("id")); } - public List> getProperties(ResourceLocation resourceLocation, Item item) { + @Override + public List> getProperties(String resourceLocation) { + Item item = getServerRegistries().registryOrThrow(Registries.ITEM).get(new ResourceLocation(resourceLocation)); List> maps = new ArrayList<>(); maps.add(getPropertiesForItem(resourceLocation, item)); return maps; } - private Map getPropertiesForItem(ResourceLocation resourceLocation, Item item) { + private Map getPropertiesForItem(String resourceLocation, Item item) { Map map = new TreeMap<>(); - map.put("id", resourceLocation.toString()); + map.put("id", resourceLocation); map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); map.put("maxDamage", item.getMaxDamage()); @@ -61,4 +58,3 @@ private Map getPropertiesForItem(ResourceLocation resourceLocati return map; } } - diff --git a/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..4d84b56 --- /dev/null +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,55 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.ITEM).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign", + "zombie_pigman_spawn_egg", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "carpets", + "furnace_materials", + "occludes_vibration_signals" + ); + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.19.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java similarity index 91% rename from src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java rename to 1.19.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java index 65b5ec0..4d39438 100644 --- a/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java +++ b/1.19.4/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -12,14 +12,12 @@ import net.minecraft.server.packs.repository.ServerPacksSource; import net.minecraft.world.Difficulty; import net.minecraft.world.flag.FeatureFlags; -import net.minecraft.world.level.DataPackConfig; -import net.minecraft.world.level.GameRules; -import net.minecraft.world.level.GameType; -import net.minecraft.world.level.LevelSettings; -import net.minecraft.world.level.WorldDataConfiguration; +import net.minecraft.world.level.*; import net.minecraft.world.level.levelgen.WorldOptions; import net.minecraft.world.level.storage.PrimaryLevelData; +import org.enginehub.util.minecraft.dumper.AbstractDumper; +import java.io.File; import java.util.concurrent.ExecutionException; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -29,6 +27,8 @@ public final class GameSetupUtils { public static void setupGame() { SharedConstants.tryDetectVersion(); Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); } private static final Lock lock = new ReentrantLock(); @@ -47,7 +47,7 @@ public static RegistryAccess getServerRegistries() { return localResources; } PackRepository resourcePackManager = new PackRepository( - new ServerPacksSource() + new ServerPacksSource() ); WorldDataConfiguration wdc = new WorldDataConfiguration(DataPackConfig.DEFAULT, FeatureFlags.DEFAULT_FLAGS); WorldLoader.PackConfig dataPacks = new WorldLoader.PackConfig(resourcePackManager, wdc, false, true); diff --git a/1.20.1/.gitignore b/1.20.1/.gitignore new file mode 100644 index 0000000..5502819 --- /dev/null +++ b/1.20.1/.gitignore @@ -0,0 +1,79 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log +logs/ + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/ + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Gradle template +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + diff --git a/1.20.1/build.gradle.kts b/1.20.1/build.gradle.kts new file mode 100644 index 0000000..15e3222 --- /dev/null +++ b/1.20.1/build.gradle.kts @@ -0,0 +1,12 @@ +import net.fabricmc.loom.api.LoomGradleExtensionAPI + +plugins { + id("fabric-loom") version "0.13.20" +} + +dependencies { + implementation(project(mapOf("path" to ":core"))) + minecraft("com.mojang:minecraft:1.20.1") + mappings(project.the().officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader.version")}") +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/RunAll.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/RunAll.java new file mode 100644 index 0000000..1be5b9d --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/RunAll.java @@ -0,0 +1,19 @@ +package org.enginehub.util.minecraft; + +import org.enginehub.util.minecraft.dumper.Dumper; +import org.enginehub.util.minecraft.util.GameSetupUtils; + +import java.util.ServiceLoader; + +public class RunAll { + + public static void main(String[] args) { + GameSetupUtils.setupGame(); + GameSetupUtils.getServerRegistries(); + for (Dumper dumper : ServiceLoader.load(Dumper.class)) { + System.out.println("Running dumper: " + dumper.getClass().getCanonicalName()); + dumper.run(); + System.out.println("Finished!"); + } + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java new file mode 100644 index 0000000..3093723 --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java @@ -0,0 +1,78 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BiomeTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BiomeTypesDumper().run(); + } + + public BiomeTypesDumper() { + super("com.sk89q.worldedit.world.biome", "Biome"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.BIOME).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.BIOME).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "nether", + "tall_birch_forest", + "giant_tree_taiga", + "giant_spruce_taiga", + "snowy_tundra", + "jungle_edge", + "stone_shore", + "mountains", + "wooded_mountains", + "gravelly_mountains", + "shattered_savanna", + "wooded_badlands_plateau", + "badlands_plateau", + "bamboo_jungle_hills", + "birch_forest_hills", + "dark_forest_hills", + "deep_warm_ocean", + "desert_hills", + "desert_lakes", + "giant_spruce_taiga_hills", + "giant_tree_taiga_hills", + "modified_gravelly_hills", + "jungle_hills", + "modified_badlands_plateau", + "modified_jungle", + "modified_jungle_edge", + "modified_wooded_badlands_plateau", + "mountain_edge", + "mushroom_field_shore", + "shattered_savanna_plateau", + "snowy_mountains", + "snowy_taiga_hills", + "snowy_taiga_mountains", + "swamp_hills", + "taiga_hills", + "taiga_mountains", + "tall_birch_hills", + "wooded_hills" + ); + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java similarity index 83% rename from src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java rename to 1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java index 69639eb..226e542 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -7,7 +7,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.core.Vec3i; import net.minecraft.core.registries.Registries; import net.minecraft.locale.Language; @@ -23,37 +22,28 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.VoxelShape; -import org.enginehub.util.minecraft.util.GameSetupUtils; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; public class BlockRegistryDumper extends RegistryDumper { - public static void main(String[] args) { - setupGame(); - new Default().run(); - } - - @AutoService(Dumper.class) - public static class Default implements Dumper { - @Override - public void run() { - new BlockRegistryDumper(new File("output/blocks.json")).run(); - } - } + private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); public BlockRegistryDumper(File file) { super(file); } + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + @Override public void registerAdapters(GsonBuilder builder) { super.registerAdapters(builder); @@ -63,8 +53,8 @@ public void registerAdapters(GsonBuilder builder) { } @Override - public Registry getRegistry() { - return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.BLOCK); + public Collection getIds() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).keySet().stream().map(ResourceLocation::toString).toList(); } @Override @@ -73,9 +63,10 @@ public Comparator> getComparator() { } @Override - public List> getProperties(ResourceLocation resourceLocation, Block block) { + public List> getProperties(String resourceLocation) { + Block block = getServerRegistries().registryOrThrow(Registries.BLOCK).get(new ResourceLocation(resourceLocation)); Map map = new TreeMap<>(); - map.put("id", resourceLocation.toString()); + map.put("id", resourceLocation); map.put("localizedName", Language.getInstance().getOrDefault(block.getDescriptionId())); map.put("material", getMaterial(block)); return Lists.newArrayList(map); @@ -93,12 +84,13 @@ private Map getMaterial(Block b) { Map map = new TreeMap<>(); map.put("powerSource", bs.isSignalSource()); map.put("lightValue", bs.getLightEmission()); - map.put("hardness", bs.getDestroySpeed(null, null)); + map.put("hardness", bs.getDestroySpeed(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); map.put("resistance", b.getExplosionResistance()); map.put("ticksRandomly", b.isRandomlyTicking(bs)); VoxelShape vs = bs.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); map.put("fullCube", !vs.isEmpty() && isFullCube(vs.bounds())); map.put("slipperiness", b.getFriction()); + // map.put("translucent", bs.isTranslucent(EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); map.put("liquid", bs.liquid()); map.put("solid", bs.isSolid()); map.put("movementBlocker", bs.blocksMotion()); @@ -109,21 +101,26 @@ private Map getMaterial(Block b) { map.put("fragileWhenPushed", bs.getPistonPushReaction() == PushReaction.DESTROY); map.put("unpushable", bs.getPistonPushReaction() == PushReaction.BLOCK); try { - map.put("mapColor", rgb(((MapColor)mapColorField.get(bs)).col)); + map.put("mapColor", rgb(((MapColor) mapColorField.get(bs)).col)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } - map.put("hasContainer", b instanceof EntityBlock && - (((EntityBlock) b).newBlockEntity(BlockPos.ZERO, bs) instanceof Clearable)); + map.put("hasContainer", b instanceof EntityBlock bep && bep.newBlockEntity(BlockPos.ZERO, bs) instanceof Clearable); return map; } - private static final AABB FULL_CUBE = AABB.unitCubeFromLowerCorner(Vec3.ZERO); - private boolean isFullCube(AABB aabb) { return aabb.equals(FULL_CUBE); } + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new BlockRegistryDumper(new File(OUTPUT, "blocks.json")).run(); + } + } + public static class Vec3iAdapter extends TypeAdapter { @Override public Vec3i read(final JsonReader in) { diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java new file mode 100644 index 0000000..8696ff6 --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/BlockTypesDumper.java @@ -0,0 +1,52 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class BlockTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new BlockTypesDumper().run(); + } + + public BlockTypesDumper() { + super("com.sk89q.worldedit.world.block", "Block"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.BLOCK).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "sign", + "wall_sign", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "dirt_like", + "carpets", + "lava_pool_stone_replaceables" + ); + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java new file mode 100644 index 0000000..806d11e --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -0,0 +1,138 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.minecraft.SharedConstants; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.properties.*; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class DataVersionDumper extends AbstractDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + File file = new File(OUTPUT, SharedConstants.getCurrentVersion().getDataVersion().getVersion() + ".json"); + new DataVersionDumper(file).run(); + } + } + + private final File file; + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public DataVersionDumper(File file) { + this.file = file; + } + + private Map> getTags(Registry registry) { + Map> tagCollector = new TreeMap<>(); + + registry.getTags().forEach(tagPair -> + tagCollector.put(tagPair.getFirst().location().toString(), tagPair.getSecond().stream() + .map(entry -> checkNotNull(registry.getKey(entry.value()))) + .map(ResourceLocation::toString) + .sorted() + .collect(Collectors.toList()))); + + return tagCollector; + } + + @SuppressWarnings("rawtypes") + private String getTypeName(Class clazz) { + if (clazz == EnumProperty.class) { + return "enum"; + } else if (clazz == IntegerProperty.class) { + return "int"; + } else if (clazz == BooleanProperty.class) { + return "bool"; + } else if (clazz == DirectionProperty.class) { + return "direction"; + } else { + throw new RuntimeException("Unknown property!"); + } + } + + @Override + public void run() { + // Blocks + Map> blocks = new TreeMap<>(); + for (ResourceLocation blockId : getServerRegistries().registryOrThrow(Registries.BLOCK).keySet()) { + Map bl = new TreeMap<>(); + Block block = getServerRegistries().registryOrThrow(Registries.BLOCK).get(blockId); + Map properties = new TreeMap<>(); + for (Property prop : block.defaultBlockState().getProperties()) { + Map propertyValues = new TreeMap<>(); + propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); + propertyValues.put("type", getTypeName(prop.getClass())); + properties.put(prop.getName(), propertyValues); + } + bl.put("properties", properties); + StringBuilder defaultState = new StringBuilder(); + defaultState.append(blockId.toString()); + if (!block.defaultBlockState().getValues().isEmpty()) { + List bits = new ArrayList<>(); + block.defaultBlockState().getValues().entrySet().stream() + .sorted(Comparator.comparing(e -> e.getKey().getName())) + .forEach(e -> + bits.add(e.getKey().getName() + "=" + e.getValue().toString().toLowerCase()) + ); + defaultState.append("[").append(String.join(",", bits)).append("]"); + } + bl.put("defaultstate", defaultState.toString()); + blocks.put(blockId.toString(), bl); + } + + // Items + List items = getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Entities + List entities = getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // Biomes + List biomes = getServerRegistries().registryOrThrow(Registries.BIOME).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + + // BlockTags + Map> blockTags = getTags(getServerRegistries().registryOrThrow(Registries.BLOCK)); + + // ItemTags + Map> itemTags = getTags(getServerRegistries().registryOrThrow(Registries.ITEM)); + + // EntityTags + Map> entityTags = getTags(getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE)); + + Map output = new TreeMap<>(); + output.put("blocks", blocks); + output.put("items", items); + output.put("entities", entities); + output.put("biomes", biomes); + output.put("blocktags", blockTags); + output.put("itemtags", itemTags); + output.put("entitytags", entityTags); + + try { + Files.asCharSink(file, StandardCharsets.UTF_8).write(gson.toJson(output)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java new file mode 100644 index 0000000..80d3822 --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/EntityTypesDumper.java @@ -0,0 +1,41 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class EntityTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new EntityTypesDumper().run(); + } + + public EntityTypesDumper() { + super("com.sk89q.worldedit.world.entity", "Entity"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "zombie_pigman" + ); + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java new file mode 100644 index 0000000..7db57ab --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -0,0 +1,60 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +import java.io.File; +import java.util.*; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +public class ItemRegistryDumper extends RegistryDumper { + + public static void main(String[] args) { + setupGame(); + new Default().run(); + } + + @AutoService(Dumper.class) + public static class Default implements Dumper { + @Override + public void run() { + new ItemRegistryDumper(new File(OUTPUT, "items.json")).run(); + } + } + + public ItemRegistryDumper(File file) { + super(file); + } + + @Override + public Collection getIds() { + return getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().map(ResourceLocation::toString).toList(); + } + + @Override + public Comparator> getComparator() { + return Comparator.comparing(map -> (String) map.get("id")); + } + + @Override + public List> getProperties(String resourceLocation) { + Item item = getServerRegistries().registryOrThrow(Registries.ITEM).get(new ResourceLocation(resourceLocation)); + List> maps = new ArrayList<>(); + maps.add(getPropertiesForItem(resourceLocation, item)); + return maps; + } + + private Map getPropertiesForItem(String resourceLocation, Item item) { + Map map = new TreeMap<>(); + map.put("id", resourceLocation); + map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); + map.put("maxDamage", item.getMaxDamage()); + map.put("maxStackSize", item.getMaxStackSize()); + return map; + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java new file mode 100644 index 0000000..4d84b56 --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java @@ -0,0 +1,55 @@ +package org.enginehub.util.minecraft.dumper; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterators; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; + +import java.util.Iterator; + +import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; +import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; + +@AutoService(Dumper.class) +public class ItemTypesDumper extends RegistryClassDumper { + + public static void main(String[] args) { + setupGame(); + new ItemTypesDumper().run(); + } + + public ItemTypesDumper() { + super("com.sk89q.worldedit.world.item", "Item"); + } + + @Override + protected Iterator getIds() { + return getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().map(ResourceLocation::getPath).iterator(); + } + + @Override + protected Iterator getTags() { + return getServerRegistries().registryOrThrow(Registries.ITEM).getTagNames().map(tagKey -> tagKey.location().getPath()).iterator(); + } + + @Override + protected Iterator getDeprecatedIds() { + return Iterators.forArray( + "cactus_green", + "dandelion_yellow", + "rose_red", + "sign", + "zombie_pigman_spawn_egg", + "grass_path" + ); + } + + @Override + protected Iterator getDeprecatedTags() { + return Iterators.forArray( + "carpets", + "furnace_materials", + "occludes_vibration_signals" + ); + } +} diff --git a/1.20.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/1.20.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java new file mode 100644 index 0000000..4d39438 --- /dev/null +++ b/1.20.1/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -0,0 +1,72 @@ +package org.enginehub.util.minecraft.util; + +import com.mojang.serialization.Lifecycle; +import net.minecraft.SharedConstants; +import net.minecraft.Util; +import net.minecraft.commands.Commands; +import net.minecraft.core.RegistryAccess; +import net.minecraft.server.Bootstrap; +import net.minecraft.server.WorldLoader; +import net.minecraft.server.WorldStem; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.world.Difficulty; +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.level.*; +import net.minecraft.world.level.levelgen.WorldOptions; +import net.minecraft.world.level.storage.PrimaryLevelData; +import org.enginehub.util.minecraft.dumper.AbstractDumper; + +import java.io.File; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public final class GameSetupUtils { + + public static void setupGame() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + + AbstractDumper.OUTPUT = new File("output/" + SharedConstants.getCurrentVersion().getName()); + } + + private static final Lock lock = new ReentrantLock(); + private static final GameRules GAME_RULES = Util.make(new GameRules(), gameRules -> { + gameRules.getRule(GameRules.RULE_DOMOBSPAWNING).set(false, null); + gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).set(false, null); + }); + private static RegistryAccess SERVER_REGISTRY_MANAGER; + + public static RegistryAccess getServerRegistries() { + setupGame(); + lock.lock(); + try { + RegistryAccess localResources = SERVER_REGISTRY_MANAGER; + if (localResources != null) { + return localResources; + } + PackRepository resourcePackManager = new PackRepository( + new ServerPacksSource() + ); + WorldDataConfiguration wdc = new WorldDataConfiguration(DataPackConfig.DEFAULT, FeatureFlags.DEFAULT_FLAGS); + WorldLoader.PackConfig dataPacks = new WorldLoader.PackConfig(resourcePackManager, wdc, false, true); + WorldLoader.InitConfig serverConfig = new WorldLoader.InitConfig(dataPacks, Commands.CommandSelection.DEDICATED, 4); + + WorldStem saveLoader = Util.blockUntilDone(executor -> WorldLoader.load(serverConfig, (dataLoadContext) -> { + LevelSettings dataGenLevel = new LevelSettings("Data Gen Level", GameType.CREATIVE, false, Difficulty.NORMAL, true, GAME_RULES, dataLoadContext.dataConfiguration()); + RegistryAccess.Frozen immutable = dataLoadContext.datapackDimensions().freeze(); + + PrimaryLevelData saveProperties = new PrimaryLevelData(dataGenLevel, WorldOptions.DEMO_OPTIONS, PrimaryLevelData.SpecialWorldProperty.FLAT, Lifecycle.stable()); + return new WorldLoader.DataLoadOutput<>(saveProperties, immutable); + }, WorldStem::new, Util.backgroundExecutor(), executor)).get(); + return SERVER_REGISTRY_MANAGER = saveLoader.registries().compositeAccess(); + } catch (ExecutionException e) { + throw new RuntimeException(e.getCause()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } finally { + lock.unlock(); + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 8a4a410..404e700 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,31 +1,32 @@ -import net.fabricmc.loom.api.LoomGradleExtensionAPI - plugins { - id("fabric-loom") version "0.12.47" -} - -repositories { - maven { - name = "Fabric" - url = uri("https://maven.fabricmc.net/") - } - mavenCentral() + java } -dependencies { - "minecraft"("com.mojang:minecraft:1.20.1") - "mappings"(project.the().officialMojangMappings()) - "modImplementation"("net.fabricmc:fabric-loader:0.14.21") +allprojects { + apply() - "implementation"("com.squareup:javapoet:1.13.0") + repositories { + mavenCentral() + gradlePluginPortal() + maven { + name = "Fabric" + url = uri("https://maven.fabricmc.net/") + } + } - val autoServiceVersion = "1.0.1" - "compileOnly"("com.google.auto.service:auto-service-annotations:$autoServiceVersion") - "annotationProcessor"("com.google.auto.service:auto-service:$autoServiceVersion") + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } + } } -plugins.withId("java") { - the().toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) +subprojects { + dependencies { + implementation("com.google.guava:guava:31.1-jre") + implementation("com.google.code.gson:gson:2.10.1") + implementation("com.squareup:javapoet:${project.property("javapoet.version")}") + compileOnly("com.google.auto.service:auto-service-annotations:${project.property("autoservice.version")}") + annotationProcessor("com.google.auto.service:auto-service:${project.property("autoservice.version")}") } } diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/core/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 0000000..e69de29 diff --git a/core/src/main/java/org/enginehub/util/minecraft/dumper/AbstractDumper.java b/core/src/main/java/org/enginehub/util/minecraft/dumper/AbstractDumper.java new file mode 100644 index 0000000..279bac6 --- /dev/null +++ b/core/src/main/java/org/enginehub/util/minecraft/dumper/AbstractDumper.java @@ -0,0 +1,24 @@ +package org.enginehub.util.minecraft.dumper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public abstract class AbstractDumper implements Dumper { + /** + * The output directory for the files. Is set in each individual module to "output/(Minecraft version)". + */ + public static File OUTPUT = null; + + protected AbstractDumper() { + Path outputPath = OUTPUT.toPath(); + if (!Files.exists(outputPath)) { + try { + Files.createDirectories(outputPath); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/Dumper.java b/core/src/main/java/org/enginehub/util/minecraft/dumper/Dumper.java similarity index 100% rename from src/main/java/org/enginehub/util/minecraft/dumper/Dumper.java rename to core/src/main/java/org/enginehub/util/minecraft/dumper/Dumper.java diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java b/core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java similarity index 52% rename from src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java rename to core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java index 59ff1c2..018bbd2 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java +++ b/core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java @@ -4,38 +4,22 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterators; import com.google.common.io.MoreFiles; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.JavaFile; -import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.TypeSpec; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; -import org.enginehub.util.minecraft.util.GameSetupUtils; +import com.squareup.javapoet.*; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Iterator; import java.util.Set; import java.util.function.UnaryOperator; import java.util.regex.Pattern; -import static javax.lang.model.element.Modifier.FINAL; -import static javax.lang.model.element.Modifier.PRIVATE; -import static javax.lang.model.element.Modifier.PUBLIC; -import static javax.lang.model.element.Modifier.STATIC; +import static javax.lang.model.element.Modifier.*; -public abstract class RegistryClassDumper implements Dumper { +public abstract class RegistryClassDumper extends AbstractDumper { private static final ClassName JAVAX_NULLABLE = - ClassName.get("javax.annotation", "Nullable"); - private static final Path OUTPUT_DIRECTORY = Paths.get("output"); + ClassName.get("javax.annotation", "Nullable"); private static final String FOUR_SPACES = Strings.repeat(" ", 4); private static UnaryOperator inlineAnnotation(String name) { @@ -57,33 +41,33 @@ private static String makePlural(String name) { } protected record DumperInfo(ClassName type, boolean nullable) { - private void generate(Iterator ids, Iterator deprecatedIdsIter) { - Set deprecatedIds = ImmutableSortedSet.copyOf(deprecatedIdsIter); - Set resources = ImmutableSortedSet - .naturalOrder() - .addAll(ids) - .addAll(deprecatedIds) - .build(); + private void generate(Iterator ids, Iterator deprecatedIdsIter) { + Set deprecatedIds = ImmutableSortedSet.copyOf(deprecatedIdsIter); + Set resources = ImmutableSortedSet + .naturalOrder() + .addAll(ids) + .addAll(deprecatedIds) + .build(); ClassName pluralType = type.peerClass(makePlural(type.simpleName())); TypeSpec.Builder builder = TypeSpec.classBuilder(pluralType); builder.addModifiers(PUBLIC, FINAL); builder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class) - .addMember("value", "$S", "unused") - .build()); + .addMember("value", "$S", "unused") + .build()); builder.addJavadoc( - "Stores a list of common {@link $1T $2N}.\n\n@see $1T", - type, pluralType.simpleName() + "Stores a list of common {@link $1T $2N}.\n\n@see $1T", + type, pluralType.simpleName() ); builder.addMethod(MethodSpec.constructorBuilder() - .addModifiers(PRIVATE) - .build()); + .addModifiers(PRIVATE) + .build()); builder.addMethod(createGetMethod()); - for (ResourceLocation resourceLocation : resources) { - String name = resourceLocation.getPath().toUpperCase().replace('/', '_'); + for (String resourceLocation : resources) { + String name = resourceLocation.toUpperCase().replace('/', '_'); FieldSpec.Builder fieldBuilder = FieldSpec.builder( - type, - name, - PUBLIC, STATIC, FINAL + type, + name, + PUBLIC, STATIC, FINAL ); if (deprecatedIds.contains(resourceLocation)) { fieldBuilder.addAnnotation(Deprecated.class); @@ -96,12 +80,12 @@ private void generate(Iterator ids, Iterator } TypeSpec spec = builder.build(); JavaFile javaFile = JavaFile.builder(type.packageName(), spec) - .indent(FOUR_SPACES) - .skipJavaLangImports(true) - .build(); + .indent(FOUR_SPACES) + .skipJavaLangImports(true) + .build(); try { - Path outputFile = OUTPUT_DIRECTORY.resolve(spec.name + ".java"); + Path outputFile = OUTPUT.toPath().resolve(spec.name + ".java"); String content = fixContent(javaFile.toString()); MoreFiles.asCharSink(outputFile, StandardCharsets.UTF_8).write(content); } catch (IOException e) { @@ -112,21 +96,21 @@ private void generate(Iterator ids, Iterator private MethodSpec createGetMethod() { MethodSpec.Builder builder = MethodSpec.methodBuilder("get"); builder - .addJavadoc("Gets the {@link $T} associated with the given id.", type) - .addModifiers(PUBLIC, STATIC) - .addParameter(String.class, "id"); + .addJavadoc("Gets the {@link $T} associated with the given id.", type) + .addModifiers(PUBLIC, STATIC) + .addParameter(String.class, "id"); if (nullable) { builder.returns(type.annotated(AnnotationSpec.builder(JAVAX_NULLABLE).build())) - .addStatement("return $T.REGISTRY.get(id)", type); + .addStatement("return $T.REGISTRY.get(id)", type); } else { builder.returns(type) - .addCode(CodeBlock.builder() - .addStatement("$1T entry = $1T.REGISTRY.get(id)", type) - .beginControlFlow("if (entry == null)") - .addStatement("return new $T(id)", type) - .endControlFlow() - .addStatement("return entry") - .build()); + .addCode(CodeBlock.builder() + .addStatement("$1T entry = $1T.REGISTRY.get(id)", type) + .beginControlFlow("if (entry == null)") + .addStatement("return new $T(id)", type) + .endControlFlow() + .addStatement("return entry") + .build()); } return builder.build(); } @@ -137,35 +121,39 @@ private String fixContent(String content) { } content = INLINE_DEPRECATED.apply(content); content = content.replace(");\n\n", ");\n") - .replace(FOUR_SPACES + "private ", "\n" + FOUR_SPACES + "private "); + .replace(FOUR_SPACES + "private ", "\n" + FOUR_SPACES + "private "); return content; } } - private final ResourceKey> key; private final DumperInfo idDumper; private final DumperInfo tagDumper; - protected RegistryClassDumper(ResourceKey> key, String packageName, String baseName) { - this.key = key; + protected RegistryClassDumper(String packageName, String baseName) { this.idDumper = new DumperInfo(ClassName.get(packageName, baseName + "Type"), true); this.tagDumper = new DumperInfo(ClassName.get(packageName, baseName + "Category"), false); } - protected Iterator getDeprecatedIds() { + protected Iterator getIds() { return Iterators.forArray(); } - protected Iterator getDeprecatedTags() { + protected Iterator getTags() { + return Iterators.forArray(); + } + + protected Iterator getDeprecatedIds() { + return Iterators.forArray(); + } + + protected Iterator getDeprecatedTags() { return Iterators.forArray(); } @Override public void run() { - var registry = GameSetupUtils.getServerRegistries().registryOrThrow(key); - - idDumper.generate(registry.keySet().iterator(), getDeprecatedIds()); - tagDumper.generate(registry.getTagNames().map(TagKey::location).iterator(), getDeprecatedTags()); + idDumper.generate(getIds(), getDeprecatedIds()); + tagDumper.generate(getTags(), getDeprecatedTags()); } -} +} \ No newline at end of file diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java b/core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java similarity index 66% rename from src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java rename to core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java index 5b69967..1ebf416 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java +++ b/core/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java @@ -3,18 +3,17 @@ import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -abstract class RegistryDumper implements Dumper { +abstract class RegistryDumper extends AbstractDumper { private final File file; private final Gson gson; @@ -23,7 +22,7 @@ protected RegistryDumper(File file) { this.file = file; GsonBuilder builder = new GsonBuilder(); registerAdapters(builder); - this.gson = builder.create(); + gson = builder.create(); } public void registerAdapters(GsonBuilder builder) { @@ -32,16 +31,10 @@ public void registerAdapters(GsonBuilder builder) { @Override public void run() { - Registry registry = getRegistry(); - ImmutableList> list = ImmutableList.sortedCopyOf( - getComparator(), - getRegistry().keySet().stream() - .flatMap(v -> getProperties(v, registry.get(v)).stream()) - .collect(Collectors.toList()) - ); + ImmutableList> list = ImmutableList.sortedCopyOf(getComparator(), getIds().stream().flatMap(v -> getProperties(v).stream()).collect(Collectors.toList())); String out = gson.toJson(list); - this.write(out); + write(out); System.out.println("Wrote file: " + file.getAbsolutePath()); } @@ -55,16 +48,15 @@ private void write(String s) { } protected String rgb(int i) { - int r = (i >> 16) & 0xFF; - int g = (i >> 8) & 0xFF; + int r = i >> 16 & 0xFF; + int g = i >> 8 & 0xFF; int b = i & 0xFF; return String.format("#%02x%02x%02x", r, g, b); } - public abstract List> getProperties(ResourceLocation resourceLocation, V object); + public abstract List> getProperties(String resourceLocation); - public abstract Registry getRegistry(); + public abstract Collection getIds(); public abstract Comparator> getComparator(); } - diff --git a/gradle.properties b/gradle.properties index 3be0ee3..5a43532 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,8 @@ group=org.enginehub version=1.0.0-SNAPSHOT + org.gradle.jvmargs=-Xmx2G + +fabric_loader.version=0.14.21 +javapoet.version=1.13.0 +autoservice.version=1.0.1 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fc..ac72c34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 index 1b6c787..0adc8e1 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +198,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/output/.gitignore b/output/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/output/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 690f1c4..08d725d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,12 +1,21 @@ rootProject.name = "MCUtils" +include("core") +include("1.14.4") +include("1.15.2") +include("1.16.5") +include("1.17.1") +include("1.18.2") +include("1.19.4") +include("1.20.1") + pluginManagement { repositories { - jcenter() + mavenCentral() + gradlePluginPortal() maven { name = "Fabric" url = uri("https://maven.fabricmc.net/") } - gradlePluginPortal() } } diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java deleted file mode 100644 index 41f3ceb..0000000 --- a/src/main/java/org/enginehub/util/minecraft/dumper/BiomeTypesDumper.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.enginehub.util.minecraft.dumper; - -import com.google.auto.service.AutoService; -import com.google.common.collect.Iterators; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; - -import java.util.Iterator; - -import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; - -@AutoService(Dumper.class) -public class BiomeTypesDumper extends RegistryClassDumper { - - public static void main(String[] args) { - setupGame(); - new BiomeTypesDumper().run(); - } - - public BiomeTypesDumper() { - super( - Registries.BIOME, - "com.sk89q.worldedit.world.biome", "Biome" - ); - } - - @Override - protected Iterator getDeprecatedIds() { - return Iterators.forArray( - new ResourceLocation("nether"), - new ResourceLocation("tall_birch_forest"), - new ResourceLocation("giant_tree_taiga"), - new ResourceLocation("giant_spruce_taiga"), - new ResourceLocation("snowy_tundra"), - new ResourceLocation("jungle_edge"), - new ResourceLocation("stone_shore"), - new ResourceLocation("mountains"), - new ResourceLocation("wooded_mountains"), - new ResourceLocation("gravelly_mountains"), - new ResourceLocation("shattered_savanna"), - new ResourceLocation("wooded_badlands_plateau"), - new ResourceLocation("badlands_plateau"), - new ResourceLocation("bamboo_jungle_hills"), - new ResourceLocation("birch_forest_hills"), - new ResourceLocation("dark_forest_hills"), - new ResourceLocation("deep_warm_ocean"), - new ResourceLocation("desert_hills"), - new ResourceLocation("desert_lakes"), - new ResourceLocation("giant_spruce_taiga_hills"), - new ResourceLocation("giant_tree_taiga_hills"), - new ResourceLocation("modified_gravelly_mountains"), - new ResourceLocation("jungle_hills"), - new ResourceLocation("modified_badlands_plateau"), - new ResourceLocation("modified_jungle"), - new ResourceLocation("modified_jungle_edge"), - new ResourceLocation("modified_wooded_badlands_plateau"), - new ResourceLocation("mountain_edge"), - new ResourceLocation("mushroom_field_shore"), - new ResourceLocation("shattered_savanna_plateau"), - new ResourceLocation("snowy_mountains"), - new ResourceLocation("snowy_taiga_hills"), - new ResourceLocation("snowy_taiga_mountains"), - new ResourceLocation("swamp_hills"), - new ResourceLocation("taiga_hills"), - new ResourceLocation("taiga_mountains"), - new ResourceLocation("tall_birch_hills"), - new ResourceLocation("wooded_hills") - ); - } -} - diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java deleted file mode 100644 index 5722c14..0000000 --- a/src/main/java/org/enginehub/util/minecraft/dumper/ItemTypesDumper.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.enginehub.util.minecraft.dumper; - -import com.google.auto.service.AutoService; -import com.google.common.collect.Iterators; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; - -import java.util.Iterator; - -import static org.enginehub.util.minecraft.util.GameSetupUtils.setupGame; - -@AutoService(Dumper.class) -public class ItemTypesDumper extends RegistryClassDumper { - - public static void main(String[] args) { - setupGame(); - new ItemTypesDumper().run(); - } - - public ItemTypesDumper() { - super( - Registries.ITEM, - "com.sk89q.worldedit.world.item", "Item" - ); - } - - @Override - protected Iterator getDeprecatedIds() { - return Iterators.forArray( - new ResourceLocation("cactus_green"), - new ResourceLocation("dandelion_yellow"), - new ResourceLocation("rose_red"), - new ResourceLocation("sign"), - new ResourceLocation("zombie_pigman_spawn_egg"), - new ResourceLocation("grass_path") - ); - } - - @Override - protected Iterator getDeprecatedTags() { - return Iterators.forArray( - new ResourceLocation("carpets"), - new ResourceLocation("furnace_materials"), - new ResourceLocation("occludes_vibration_signals") - ); - } -}