mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 04:00:30 +00:00
Clean up data generators a little
This commit is contained in:
parent
0c4fd2b29e
commit
bdf590fa30
@ -8,9 +8,9 @@ import org.jetbrains.gradle.ext.settings
|
||||
|
||||
plugins {
|
||||
// Build
|
||||
id("net.minecraftforge.gradle")
|
||||
id("cc-tweaked.forge")
|
||||
id("cc-tweaked.gametest")
|
||||
alias(libs.plugins.mixinGradle)
|
||||
id("org.parchmentmc.librarian.forgegradle")
|
||||
alias(libs.plugins.shadow)
|
||||
// Publishing
|
||||
alias(libs.plugins.curseForgeGradle)
|
||||
@ -21,7 +21,6 @@ plugins {
|
||||
id("org.jetbrains.gradle.plugin.idea-ext")
|
||||
|
||||
id("cc-tweaked.illuaminate")
|
||||
id("cc-tweaked.gametest")
|
||||
id("cc-tweaked.publishing")
|
||||
id("cc-tweaked")
|
||||
}
|
||||
@ -36,10 +35,6 @@ cct {
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
// ForgeGradle adds a dep on the clientClasses task, despite forge-api coming from a separate project. Register an
|
||||
// empty one.
|
||||
register("client")
|
||||
|
||||
main {
|
||||
resources.srcDir("src/generated/resources")
|
||||
}
|
||||
@ -129,10 +124,6 @@ minecraft {
|
||||
property("forge.logging.console.level", "info")
|
||||
}
|
||||
}
|
||||
|
||||
mappings("parchment", "${libs.versions.parchmentMc.get()}-${libs.versions.parchment.get()}-$mcVersion")
|
||||
|
||||
accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))
|
||||
}
|
||||
|
||||
mixin {
|
||||
@ -151,7 +142,6 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft("net.minecraftforge:forge:$mcVersion-${libs.versions.forge.get()}")
|
||||
annotationProcessor("org.spongepowered:mixin:0.8.5-SQUID:processor")
|
||||
|
||||
errorprone(project(":lints"))
|
||||
|
@ -42,10 +42,11 @@ repositories {
|
||||
includeGroup("org.squiddev")
|
||||
includeGroup("cc.tweaked")
|
||||
// Things we mirror
|
||||
includeGroup("com.blamejared.crafttweaker")
|
||||
includeGroup("commoble.morered")
|
||||
includeGroup("maven.modrinth")
|
||||
includeGroup("me.shedaniel")
|
||||
includeGroup("me.shedaniel.cloth")
|
||||
includeGroup("mezz.jei")
|
||||
includeModule("net.minecraftforge", "forgeconfigapiport-fabric")
|
||||
// Until https://github.com/SpongePowered/Mixin/pull/593 is merged
|
||||
includeModule("org.spongepowered", "mixin")
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import static dan200.computercraft.api.ComputerCraftTags.Blocks.*;
|
||||
|
||||
class BlockTagsGenerator extends BlockTagsProvider {
|
||||
BlockTagsGenerator(DataGenerator generator, ExistingFileHelper helper) {
|
||||
super(generator, ComputerCraftAPI.MOD_ID, helper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void addTags() {
|
||||
// Items
|
||||
tag(COMPUTER).add(
|
||||
ModRegistry.Blocks.COMPUTER_NORMAL.get(),
|
||||
ModRegistry.Blocks.COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Blocks.COMPUTER_COMMAND.get()
|
||||
);
|
||||
tag(TURTLE).add(ModRegistry.Blocks.TURTLE_NORMAL.get(), ModRegistry.Blocks.TURTLE_ADVANCED.get());
|
||||
tag(WIRED_MODEM).add(ModRegistry.Blocks.CABLE.get(), ModRegistry.Blocks.WIRED_MODEM_FULL.get());
|
||||
tag(MONITOR).add(ModRegistry.Blocks.MONITOR_NORMAL.get(), ModRegistry.Blocks.MONITOR_ADVANCED.get());
|
||||
|
||||
tag(TURTLE_ALWAYS_BREAKABLE).addTags(BlockTags.LEAVES).add(
|
||||
net.minecraft.world.level.block.Blocks.BAMBOO, net.minecraft.world.level.block.Blocks.BAMBOO_SAPLING // Bamboo isn't instabreak for some odd reason.
|
||||
);
|
||||
|
||||
tag(TURTLE_SHOVEL_BREAKABLE).addTag(BlockTags.MINEABLE_WITH_SHOVEL).add(
|
||||
net.minecraft.world.level.block.Blocks.MELON,
|
||||
net.minecraft.world.level.block.Blocks.PUMPKIN,
|
||||
net.minecraft.world.level.block.Blocks.CARVED_PUMPKIN,
|
||||
net.minecraft.world.level.block.Blocks.JACK_O_LANTERN
|
||||
);
|
||||
|
||||
tag(TURTLE_HOE_BREAKABLE).addTags(
|
||||
BlockTags.CROPS,
|
||||
BlockTags.MINEABLE_WITH_HOE
|
||||
).add(
|
||||
net.minecraft.world.level.block.Blocks.CACTUS,
|
||||
net.minecraft.world.level.block.Blocks.MELON,
|
||||
net.minecraft.world.level.block.Blocks.PUMPKIN,
|
||||
net.minecraft.world.level.block.Blocks.CARVED_PUMPKIN,
|
||||
net.minecraft.world.level.block.Blocks.JACK_O_LANTERN
|
||||
);
|
||||
|
||||
tag(TURTLE_SWORD_BREAKABLE).addTags(BlockTags.WOOL).add(net.minecraft.world.level.block.Blocks.COBWEB);
|
||||
|
||||
// Make all blocks aside from command computer mineable.
|
||||
tag(BlockTags.MINEABLE_WITH_PICKAXE).add(
|
||||
ModRegistry.Blocks.COMPUTER_NORMAL.get(),
|
||||
ModRegistry.Blocks.COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Blocks.TURTLE_NORMAL.get(),
|
||||
ModRegistry.Blocks.TURTLE_ADVANCED.get(),
|
||||
ModRegistry.Blocks.SPEAKER.get(),
|
||||
ModRegistry.Blocks.DISK_DRIVE.get(),
|
||||
ModRegistry.Blocks.PRINTER.get(),
|
||||
ModRegistry.Blocks.MONITOR_NORMAL.get(),
|
||||
ModRegistry.Blocks.MONITOR_ADVANCED.get(),
|
||||
ModRegistry.Blocks.WIRELESS_MODEM_NORMAL.get(),
|
||||
ModRegistry.Blocks.WIRELESS_MODEM_ADVANCED.get(),
|
||||
ModRegistry.Blocks.WIRED_MODEM_FULL.get(),
|
||||
ModRegistry.Blocks.CABLE.get()
|
||||
);
|
||||
}
|
||||
}
|
64
src/main/java/dan200/computercraft/data/DataProviders.java
Normal file
64
src/main/java/dan200/computercraft/data/DataProviders.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.models.BlockModelGenerators;
|
||||
import net.minecraft.data.models.ItemModelGenerators;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* All data providers for ComputerCraft. We require a mod-loader abstraction {@link DataProviders.GeneratorFactory} to
|
||||
* handle the slight differences between how Forge and Fabric expose Minecraft's data providers.
|
||||
*/
|
||||
public final class DataProviders {
|
||||
private DataProviders() {
|
||||
}
|
||||
|
||||
public static void add(DataGenerator generator, GeneratorFactory generators, boolean includeServer, boolean includeClient) {
|
||||
var turtleUpgrades = new TurtleUpgradeGenerator(generator);
|
||||
var pocketUpgrades = new PocketUpgradeGenerator(generator);
|
||||
|
||||
generator.addProvider(includeServer, turtleUpgrades);
|
||||
generator.addProvider(includeServer, pocketUpgrades);
|
||||
generator.addProvider(includeServer, generators.recipes(new RecipeGenerator(turtleUpgrades, pocketUpgrades)::addRecipes));
|
||||
|
||||
var blockTags = generators.blockTags(TagProvider::blockTags);
|
||||
generator.addProvider(includeServer, blockTags);
|
||||
generator.addProvider(includeServer, generators.itemTags(TagProvider::itemTags, blockTags));
|
||||
|
||||
for (var provider : generators.lootTable(LootTableGenerator.getTables())) {
|
||||
generator.addProvider(includeServer, provider);
|
||||
}
|
||||
|
||||
generator.addProvider(includeClient, generators.models(BlockModelGenerator::addBlockModels, ItemModelGenerator::addItemModels));
|
||||
}
|
||||
|
||||
interface GeneratorFactory {
|
||||
DataProvider recipes(Consumer<Consumer<FinishedRecipe>> recipes);
|
||||
|
||||
List<DataProvider> lootTable(List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> tables);
|
||||
|
||||
TagsProvider<Block> blockTags(Consumer<TagProvider.TagConsumer<Block>> tags);
|
||||
|
||||
TagsProvider<Item> itemTags(Consumer<TagProvider.ItemTagConsumer> tags, TagsProvider<Block> blocks);
|
||||
|
||||
DataProvider models(Consumer<BlockModelGenerators> blocks, Consumer<ItemModelGenerators> items);
|
||||
}
|
||||
}
|
@ -5,28 +5,110 @@
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
import net.minecraft.data.models.BlockModelGenerators;
|
||||
import net.minecraft.data.models.ItemModelGenerators;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeProvider;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.LootTables;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class Generators {
|
||||
@SubscribeEvent
|
||||
public static void gather(GatherDataEvent event) {
|
||||
var generator = event.getGenerator();
|
||||
var existingFiles = event.getExistingFileHelper();
|
||||
DataProviders.add(
|
||||
generator, new GeneratorFactoryImpl(generator, event.getExistingFileHelper()),
|
||||
event.includeServer(), event.includeClient()
|
||||
);
|
||||
}
|
||||
|
||||
var turtleUpgrades = new TurtleUpgradeGenerator(generator);
|
||||
var pocketUpgrades = new PocketUpgradeGenerator(generator);
|
||||
generator.addProvider(event.includeServer(), turtleUpgrades);
|
||||
generator.addProvider(event.includeServer(), pocketUpgrades);
|
||||
private record GeneratorFactoryImpl(
|
||||
DataGenerator generator, ExistingFileHelper existingFiles
|
||||
) implements DataProviders.GeneratorFactory {
|
||||
@Override
|
||||
public DataProvider recipes(Consumer<Consumer<FinishedRecipe>> recipes) {
|
||||
return new RecipeProvider(generator) {
|
||||
@Override
|
||||
protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer) {
|
||||
recipes.accept(consumer);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
generator.addProvider(event.includeServer(), new RecipeGenerator(generator, turtleUpgrades, pocketUpgrades));
|
||||
generator.addProvider(event.includeServer(), new LootTableGenerator(generator));
|
||||
generator.addProvider(event.includeClient(), new ModelProvider(generator, BlockModelGenerator::addBlockModels, ItemModelGenerator::addItemModels));
|
||||
@Override
|
||||
public List<DataProvider> lootTable(List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> tables) {
|
||||
return List.of(new LootTableProvider(generator) {
|
||||
@Override
|
||||
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
var blockTags = new BlockTagsGenerator(generator, existingFiles);
|
||||
generator.addProvider(event.includeServer(), blockTags);
|
||||
generator.addProvider(event.includeServer(), new ItemTagsGenerator(generator, blockTags, existingFiles));
|
||||
@Override
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext tracker) {
|
||||
map.forEach((id, table) -> LootTables.validate(tracker, id, table));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagsProvider<Block> blockTags(Consumer<TagProvider.TagConsumer<Block>> tags) {
|
||||
return new BlockTagsProvider(generator, ComputerCraftAPI.MOD_ID, existingFiles) {
|
||||
@Override
|
||||
protected void addTags() {
|
||||
tags.accept(this::tag);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagsProvider<Item> itemTags(Consumer<TagProvider.ItemTagConsumer> tags, TagsProvider<Block> blocks) {
|
||||
return new ItemTagsProvider(generator, (BlockTagsProvider) blocks, ComputerCraftAPI.MOD_ID, existingFiles) {
|
||||
@Override
|
||||
protected void addTags() {
|
||||
var self = this;
|
||||
tags.accept(new TagProvider.ItemTagConsumer() {
|
||||
@Override
|
||||
public TagAppender<Item> tag(TagKey<Item> tag) {
|
||||
return self.tag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(TagKey<Block> block, TagKey<Item> item) {
|
||||
self.copy(block, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataProvider models(Consumer<BlockModelGenerators> blocks, Consumer<ItemModelGenerators> items) {
|
||||
return new ModelProvider(generator, blocks, items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.ComputerCraftTags.Blocks;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import static dan200.computercraft.api.ComputerCraftTags.Items.*;
|
||||
|
||||
class ItemTagsGenerator extends ItemTagsProvider {
|
||||
ItemTagsGenerator(DataGenerator generator, BlockTagsGenerator blockTags, ExistingFileHelper helper) {
|
||||
super(generator, blockTags, ComputerCraftAPI.MOD_ID, helper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags() {
|
||||
copy(Blocks.COMPUTER, COMPUTER);
|
||||
copy(Blocks.TURTLE, TURTLE);
|
||||
tag(WIRED_MODEM).add(ModRegistry.Items.WIRED_MODEM.get(), ModRegistry.Items.WIRED_MODEM_FULL.get());
|
||||
copy(Blocks.MONITOR, MONITOR);
|
||||
|
||||
tag(ItemTags.PIGLIN_LOVED).add(
|
||||
ModRegistry.Items.COMPUTER_ADVANCED.get(), ModRegistry.Items.TURTLE_ADVANCED.get(),
|
||||
ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Items.MONITOR_ADVANCED.get()
|
||||
);
|
||||
}
|
||||
}
|
@ -15,14 +15,10 @@ import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
||||
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.storage.loot.LootPool;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.LootTables;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
import net.minecraft.world.level.storage.loot.entries.DynamicLoot;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
|
||||
@ -36,29 +32,18 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class LootTableGenerator extends LootTableProvider {
|
||||
LootTableGenerator(DataGenerator generator) {
|
||||
super(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
||||
class LootTableGenerator {
|
||||
public static List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
||||
return List.of(
|
||||
Pair.of(() -> LootTableGenerator::registerBlocks, LootContextParamSets.BLOCK),
|
||||
Pair.of(() -> LootTableGenerator::registerGeneric, LootContextParamSets.ALL_PARAMS)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker) {
|
||||
map.forEach((id, table) -> LootTables.validate(validationtracker, id, table));
|
||||
}
|
||||
|
||||
private static void registerBlocks(BiConsumer<ResourceLocation, LootTable.Builder> add) {
|
||||
namedBlockDrop(add, ModRegistry.Blocks.DISK_DRIVE);
|
||||
selfDrop(add, ModRegistry.Blocks.MONITOR_NORMAL);
|
||||
|
@ -21,8 +21,10 @@ import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.recipes.*;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.data.recipes.SpecialRecipeBuilder;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@ -44,20 +46,17 @@ import java.util.function.Consumer;
|
||||
import static dan200.computercraft.api.ComputerCraftTags.Items.COMPUTER;
|
||||
import static dan200.computercraft.api.ComputerCraftTags.Items.WIRED_MODEM;
|
||||
|
||||
class RecipeGenerator extends RecipeProvider {
|
||||
class RecipeGenerator {
|
||||
private final RecipeIngredients ingredients = PlatformHelper.get().getRecipeIngredients();
|
||||
private final TurtleUpgradeDataProvider turtleUpgrades;
|
||||
private final PocketUpgradeDataProvider pocketUpgrades;
|
||||
|
||||
RecipeGenerator(DataGenerator generator, TurtleUpgradeDataProvider turtleUpgrades, PocketUpgradeDataProvider pocketUpgrades) {
|
||||
super(generator);
|
||||
|
||||
RecipeGenerator(TurtleUpgradeDataProvider turtleUpgrades, PocketUpgradeDataProvider pocketUpgrades) {
|
||||
this.turtleUpgrades = turtleUpgrades;
|
||||
this.pocketUpgrades = pocketUpgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildCraftingRecipes(Consumer<FinishedRecipe> add) {
|
||||
public void addRecipes(Consumer<FinishedRecipe> add) {
|
||||
basicRecipes(add);
|
||||
diskColours(add);
|
||||
pocketUpgrades(add);
|
||||
|
103
src/main/java/dan200/computercraft/data/TagProvider.java
Normal file
103
src/main/java/dan200/computercraft/data/TagProvider.java
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftTags;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
/**
|
||||
* Generators for block and item tags.
|
||||
* <p>
|
||||
* We cannot trivially extend {@link TagsProvider}, as Forge requires an {@code ExistingFileHelper} as a constructor
|
||||
* argument. Instead, we write our tags to the wrapper interface {@link TagConsumer}.
|
||||
*/
|
||||
class TagProvider {
|
||||
public static void blockTags(TagConsumer<Block> tags) {
|
||||
tags.tag(ComputerCraftTags.Blocks.COMPUTER).add(
|
||||
ModRegistry.Blocks.COMPUTER_NORMAL.get(),
|
||||
ModRegistry.Blocks.COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Blocks.COMPUTER_COMMAND.get()
|
||||
);
|
||||
tags.tag(ComputerCraftTags.Blocks.TURTLE).add(ModRegistry.Blocks.TURTLE_NORMAL.get(), ModRegistry.Blocks.TURTLE_ADVANCED.get());
|
||||
tags.tag(ComputerCraftTags.Blocks.WIRED_MODEM).add(ModRegistry.Blocks.CABLE.get(), ModRegistry.Blocks.WIRED_MODEM_FULL.get());
|
||||
tags.tag(ComputerCraftTags.Blocks.MONITOR).add(ModRegistry.Blocks.MONITOR_NORMAL.get(), ModRegistry.Blocks.MONITOR_ADVANCED.get());
|
||||
|
||||
tags.tag(ComputerCraftTags.Blocks.TURTLE_ALWAYS_BREAKABLE).addTag(BlockTags.LEAVES).add(
|
||||
Blocks.BAMBOO, Blocks.BAMBOO_SAPLING // Bamboo isn't instabreak for some odd reason.
|
||||
);
|
||||
|
||||
tags.tag(ComputerCraftTags.Blocks.TURTLE_SHOVEL_BREAKABLE).addTag(BlockTags.MINEABLE_WITH_SHOVEL).add(
|
||||
Blocks.MELON,
|
||||
Blocks.PUMPKIN,
|
||||
Blocks.CARVED_PUMPKIN,
|
||||
Blocks.JACK_O_LANTERN
|
||||
);
|
||||
|
||||
tags.tag(ComputerCraftTags.Blocks.TURTLE_HOE_BREAKABLE).addTag(BlockTags.CROPS).addTag(BlockTags.MINEABLE_WITH_HOE).add(
|
||||
Blocks.CACTUS,
|
||||
Blocks.MELON,
|
||||
Blocks.PUMPKIN,
|
||||
Blocks.CARVED_PUMPKIN,
|
||||
Blocks.JACK_O_LANTERN
|
||||
);
|
||||
|
||||
tags.tag(ComputerCraftTags.Blocks.TURTLE_SWORD_BREAKABLE).addTag(BlockTags.WOOL).add(Blocks.COBWEB);
|
||||
|
||||
// Make all blocks aside from command computer mineable.
|
||||
tags.tag(BlockTags.MINEABLE_WITH_PICKAXE).add(
|
||||
ModRegistry.Blocks.COMPUTER_NORMAL.get(),
|
||||
ModRegistry.Blocks.COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Blocks.TURTLE_NORMAL.get(),
|
||||
ModRegistry.Blocks.TURTLE_ADVANCED.get(),
|
||||
ModRegistry.Blocks.SPEAKER.get(),
|
||||
ModRegistry.Blocks.DISK_DRIVE.get(),
|
||||
ModRegistry.Blocks.PRINTER.get(),
|
||||
ModRegistry.Blocks.MONITOR_NORMAL.get(),
|
||||
ModRegistry.Blocks.MONITOR_ADVANCED.get(),
|
||||
ModRegistry.Blocks.WIRELESS_MODEM_NORMAL.get(),
|
||||
ModRegistry.Blocks.WIRELESS_MODEM_ADVANCED.get(),
|
||||
ModRegistry.Blocks.WIRED_MODEM_FULL.get(),
|
||||
ModRegistry.Blocks.CABLE.get()
|
||||
);
|
||||
}
|
||||
|
||||
public static void itemTags(ItemTagConsumer tags) {
|
||||
tags.copy(ComputerCraftTags.Blocks.COMPUTER, ComputerCraftTags.Items.COMPUTER);
|
||||
tags.copy(ComputerCraftTags.Blocks.TURTLE, ComputerCraftTags.Items.TURTLE);
|
||||
tags.tag(ComputerCraftTags.Items.WIRED_MODEM).add(ModRegistry.Items.WIRED_MODEM.get(), ModRegistry.Items.WIRED_MODEM_FULL.get());
|
||||
tags.copy(ComputerCraftTags.Blocks.MONITOR, ComputerCraftTags.Items.MONITOR);
|
||||
|
||||
tags.tag(ItemTags.PIGLIN_LOVED).add(
|
||||
ModRegistry.Items.COMPUTER_ADVANCED.get(), ModRegistry.Items.TURTLE_ADVANCED.get(),
|
||||
ModRegistry.Items.WIRELESS_MODEM_ADVANCED.get(), ModRegistry.Items.POCKET_COMPUTER_ADVANCED.get(),
|
||||
ModRegistry.Items.MONITOR_ADVANCED.get()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper over {@link TagsProvider}.
|
||||
*
|
||||
* @param <T> The type of object we're providing tags for.
|
||||
*/
|
||||
public interface TagConsumer<T> {
|
||||
TagsProvider.TagAppender<T> tag(TagKey<T> tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper over {@link ItemTagsProvider}.
|
||||
*/
|
||||
interface ItemTagConsumer extends TagConsumer<Item> {
|
||||
void copy(TagKey<Block> block, TagKey<Item> item);
|
||||
}
|
||||
}
|
@ -119,6 +119,12 @@ public final class ModRegistry {
|
||||
return BlockBehaviour.Properties.of(Material.STONE).strength(2);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties computerProperties() {
|
||||
// Computers shouldn't conduct redstone through them, so set isRedstoneConductor to false. This still allows
|
||||
// redstone to connect to computers though as it's a signal source.
|
||||
return properties().isRedstoneConductor((block, level, blockPos) -> false);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties turtleProperties() {
|
||||
return BlockBehaviour.Properties.of(Material.STONE).strength(2.5f);
|
||||
}
|
||||
@ -128,12 +134,12 @@ public final class ModRegistry {
|
||||
}
|
||||
|
||||
public static final RegistryEntry<BlockComputer<TileComputer>> COMPUTER_NORMAL = REGISTRY.register("computer_normal",
|
||||
() -> new BlockComputer<>(properties(), ComputerFamily.NORMAL, BlockEntities.COMPUTER_NORMAL));
|
||||
() -> new BlockComputer<>(computerProperties(), ComputerFamily.NORMAL, BlockEntities.COMPUTER_NORMAL));
|
||||
public static final RegistryEntry<BlockComputer<TileComputer>> COMPUTER_ADVANCED = REGISTRY.register("computer_advanced",
|
||||
() -> new BlockComputer<>(properties(), ComputerFamily.ADVANCED, BlockEntities.COMPUTER_ADVANCED));
|
||||
() -> new BlockComputer<>(computerProperties(), ComputerFamily.ADVANCED, BlockEntities.COMPUTER_ADVANCED));
|
||||
|
||||
public static final RegistryEntry<BlockComputer<TileCommandComputer>> COMPUTER_COMMAND = REGISTRY.register("computer_command", () -> new BlockComputer<>(
|
||||
BlockBehaviour.Properties.of(Material.STONE).strength(-1, 6000000.0F),
|
||||
computerProperties().strength(-1, 6000000.0F),
|
||||
ComputerFamily.COMMAND, BlockEntities.COMPUTER_COMMAND
|
||||
));
|
||||
|
||||
|
@ -21,7 +21,6 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
@ -29,7 +28,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -105,14 +103,15 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) {
|
||||
@Deprecated
|
||||
public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) {
|
||||
var tile = world.getBlockEntity(pos);
|
||||
if (tile instanceof TileComputerBase) {
|
||||
var result = getItem((TileComputerBase) tile);
|
||||
if (tile instanceof TileComputerBase computer) {
|
||||
var result = getItem(computer);
|
||||
if (!result.isEmpty()) return result;
|
||||
}
|
||||
|
||||
return super.getCloneItemStack(state, target, world, pos, player);
|
||||
return super.getCloneItemStack(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,11 +160,6 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCheckWeakPower(BlockState state, LevelReader world, BlockPos pos, Direction side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <U extends BlockEntity> BlockEntityTicker<U> getTicker(Level level, BlockState state, BlockEntityType<U> type) {
|
||||
|
Loading…
Reference in New Issue
Block a user