Skip to content

Commit

Permalink
datagen
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <daniel@shedaniel.me>
  • Loading branch information
shedaniel committed Aug 16, 2020
1 parent 9569c41 commit b81106d
Show file tree
Hide file tree
Showing 20 changed files with 981 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,9 @@ include "me.shedaniel.cloth.api:cloth-api:${project.cloth_api_version}"
#### cloth-durability-bar-api-v1
**To be implemented:**
- DurabilityBarItem: Custom durability bar display
#### cloth-dynamic-registry-api-v1
Events for listening to dynamic registries and api to add features and structures to biomes.
https://gist.github.com/shedaniel/1f819e811cefa59e414ef9f6c6d121db
#### cloth-scissors-api-v1
**Utils:**
- ScissorsStack: Stacking support for scissors
Expand Down
27 changes: 27 additions & 0 deletions build.gradle
Expand Up @@ -12,6 +12,8 @@ plugins {
id 'com.jfrog.bintray' version '1.8.4'
}

import net.fabricmc.loom.task.RunClientTask

version = project.mod_version
logger.lifecycle("Building cloth-api: " + version)
archivesBaseName = "cloth-api"
Expand Down Expand Up @@ -39,12 +41,25 @@ allprojects {
sourceCompatibility = targetCompatibility = 1.8

group = "me.shedaniel.cloth.api"

ext {
shouldGenerateData = false
}

sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
main {
resources {
srcDir 'src/generated/resources'
}
}
datagen {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}

repositories {
Expand Down Expand Up @@ -96,6 +111,16 @@ allprojects {
header rootProject.file('HEADER')
include '**/*.java'
}

if (shouldGenerateData) {
task generateData(type: RunClientTask, dependsOn: downloadAssets) {
classpath = configurations.runtimeClasspath
classpath sourceSets.main.output
classpath sourceSets.datagen.output
}

build.dependsOn generateData
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand All @@ -119,6 +144,7 @@ subprojects {

dependencies {
testmodCompile sourceSets.main.output
datagenCompile sourceSets.main.output
}

task remapMavenJar(type: Copy, dependsOn: remapJar) {
Expand Down Expand Up @@ -228,6 +254,7 @@ subprojects.each { remapJar.dependsOn("${it.path}:remapJar") }

sourceSets {
testmod
datagen
}

dependencies {
Expand Down
6 changes: 6 additions & 0 deletions cloth-datagen-api-v1/build.gradle
@@ -0,0 +1,6 @@
archivesBaseName = "cloth-datagen-api-v1"
shouldGenerateData = false

minecraft {
accessWidener(file("src/main/resources/cloth-datagen-api-v1.accessWidener"))
}
@@ -0,0 +1,81 @@
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

package me.shedaniel.cloth.test.datagen;

import me.shedaniel.cloth.api.datagen.v1.DataGeneratorHandler;
import me.shedaniel.cloth.api.datagen.v1.LootTableData;
import me.shedaniel.cloth.api.datagen.v1.RecipeData;
import me.shedaniel.cloth.api.datagen.v1.TagData;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
import net.minecraft.advancement.criterion.ImpossibleCriterion;
import net.minecraft.block.Blocks;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonFactory;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.Items;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;

import java.nio.file.Paths;

public class TestDatagen implements PreLaunchEntrypoint {
@Override
public void onPreLaunch() {
try {
DataGeneratorHandler handler = DataGeneratorHandler.create(Paths.get("../cloth-datagen-api-v1/src/generated/resource"));

LootTableData table = handler.getLootTables();
table.registerBlockDropSelf(Blocks.DIAMOND_BLOCK);
table.registerBlockDrop(Blocks.IRON_BLOCK, Items.ACACIA_FENCE);
table.register(Blocks.COAL_BLOCK, LootTableData.dropsBlockWithShears(Items.ACACIA_DOOR));
table.register(Blocks.BONE_BLOCK, LootTableData.dropsBlockWithSilkTouch(Items.DIAMOND));
table.register(Blocks.ACACIA_SLAB, LootTableData.dropsSlabs(Blocks.ACACIA_SLAB));

TagData tag = handler.getTags();
tag.block(new Identifier("thing")).append(Blocks.ACACIA_FENCE);
TagData.TagBuilder<ItemConvertible> thing = tag.item(new Identifier("thing")).append(Blocks.ACACIA_FENCE);
tag.item(new Identifier("awesome")).append(Blocks.BIRCH_SAPLING, Items.IRON_AXE).appendTag(ItemTags.ANVIL).appendTag(thing);

RecipeData recipes = handler.getRecipes();
ShapelessRecipeJsonFactory.create(Items.STONE)
.criterion("impossible", new ImpossibleCriterion.Conditions())
.input(Items.SPONGE)
.input(Items.SPONGE)
.input(Items.SPONGE)
.input(Items.SPONGE)
.input(Items.SPONGE)
.input(Items.SPONGE)
.offerTo(recipes);

handler.run();
} catch (Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}
24 changes: 24 additions & 0 deletions cloth-datagen-api-v1/src/datagen/resources/fabric.mod.json
@@ -0,0 +1,24 @@
{
"schemaVersion": 1,
"id": "cloth-datagen-api-v1-datagen",
"name": "Cloth Datagen v1: Datagen",
"description": "API for easier datagens",
"version": "${version}",
"authors": [
"shedaniel"
],
"contact": {
"homepage": "https://www.curseforge.com/minecraft/mc-mods/cloth-api",
"sources": "https://github.com/shedaniel/cloth-api",
"issues": "https://github.com/shedaniel/cloth-api/issues"
},
"entrypoints": {
"preLaunch": ["me.shedaniel.cloth.test.datagen.TestDatagen"]
},
"license": "Unlicense",
"environment": "*",
"custom": {
"modmenu:api": true,
"modmenu:parent": "cloth-api"
}
}
@@ -0,0 +1,66 @@
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

package me.shedaniel.cloth.api.datagen.v1;

import me.shedaniel.cloth.impl.datagen.DataGeneratorHandlerImpl;
import net.minecraft.Bootstrap;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DataProvider;

import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;

public interface DataGeneratorHandler extends Runnable {
static DataGeneratorHandler create(Path output) {
Bootstrap.initialize();
DataGenerator generator = new DataGenerator(output.toAbsolutePath().normalize(), Collections.emptyList());

return new DataGeneratorHandlerImpl(generator);
}

default void install(DataProvider dataProvider) {
getDataGenerator().install(dataProvider);
}

default Collection<Path> getInputs() {
return getDataGenerator().getInputs();
}

default Path getOutput() {
return getDataGenerator().getOutput();
}

DataGenerator getDataGenerator();

LootTableData getLootTables();

TagData getTags();

RecipeData getRecipes();
}
@@ -0,0 +1,87 @@
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

package me.shedaniel.cloth.api.datagen.v1;

import net.minecraft.block.Block;
import net.minecraft.data.server.BlockLootTableGenerator;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemConvertible;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.context.LootContextType;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.loot.entry.LootPoolEntry;
import net.minecraft.util.Identifier;

public interface LootTableData {
void register(LootContextType type, Identifier identifier, LootTable.Builder lootTable);

default void register(Block block, LootTable.Builder lootTable) {
register(LootContextTypes.BLOCK, block.getLootTableId(), lootTable);
}

default void register(EntityType<?> entityType, LootTable.Builder lootTable) {
register(LootContextTypes.ENTITY, entityType.getLootTableId(), lootTable);
}

default void registerBlockDropSelf(Block block) {
this.registerBlockDrop(block, block);
}

default void registerBlockDropSelfRequiresSilkTouch(Block block) {
this.registerBlockDropRequiresSilkTouch(block, block);
}

default void registerBlockDrop(Block block, ItemConvertible drop) {
this.register(block, dropsBlock(drop));
}

default void registerBlockDropRequiresSilkTouch(Block block, ItemConvertible drop) {
this.register(block, dropsBlockWithSilkTouch(drop));
}

static LootTable.Builder dropsBlock(ItemConvertible drop) {
return BlockLootTableGenerator.drops(drop);
}

static LootTable.Builder dropsBlock(Block drop, LootCondition.Builder conditionBuilder, LootPoolEntry.Builder<?> child) {
return BlockLootTableGenerator.drops(drop, conditionBuilder, child);
}

static LootTable.Builder dropsBlockWithSilkTouch(ItemConvertible drop) {
return BlockLootTableGenerator.dropsWithSilkTouch(drop);
}

static LootTable.Builder dropsBlockWithShears(ItemConvertible drop) {
return BlockLootTableGenerator.createForBlockNeedingShears(drop);
}

static LootTable.Builder dropsSlabs(Block drop) {
return BlockLootTableGenerator.createForSlabs(drop);
}
}
@@ -0,0 +1,36 @@
/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org>
*/

package me.shedaniel.cloth.api.datagen.v1;

import net.minecraft.data.server.recipe.RecipeJsonProvider;

import java.util.function.Consumer;

public interface RecipeData extends Consumer<RecipeJsonProvider> {

}

0 comments on commit b81106d

Please sign in to comment.