Skip to content

Commit

Permalink
Fully replace block module
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Jul 25, 2024
1 parent dc5c0b0 commit 6b8cc72
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 506 deletions.

This file was deleted.

2 changes: 0 additions & 2 deletions src/generated/resources/assets/examplemod/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"block.examplemod.example_block": "Test Example Block",
"block.examplemod.example_block_demo": "Test Example Block",
"block.examplemod.example_fluid": "Example Fluid",
"fluid_type.examplemod.example_fluid": "Example Fluid",
"item.examplemod.example_item": "Test Example Item",
"itemGroup.examplemod.example_tab": "Example"
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions src/generated/resources/data/minecraft/tags/block/logs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"values": [
"examplemod:example_block",
"examplemod:example_block_demo"
"examplemod:example_block"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"values": [
"examplemod:example_block",
"examplemod:example_block_demo"
"examplemod:example_block"
]
}
3 changes: 1 addition & 2 deletions src/generated/resources/data/minecraft/tags/item/planks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"values": [
"examplemod:example_block",
"examplemod:example_block_demo"
"examplemod:example_block"
]
}
7 changes: 0 additions & 7 deletions src/main/java/com/enderio/regilite/Regilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.enderio.regilite.loot.RegiliteLootTables;
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.registry.BlockEntityRegistry;
import com.enderio.regilite.registry.BlockRegistry;
import com.enderio.regilite.registry.EntityRegistry;
import com.enderio.regilite.registry.FluidRegistry;
import com.enderio.regilite.registry.ItemRegistry;
Expand Down Expand Up @@ -136,8 +135,6 @@ public void register(IEventBus modbus) {
modbus.addListener(new BlockEntityCapabilityEvents(this)::registerCapabilities);

if (FMLEnvironment.dist.isClient()) {
modbus.addListener(new ColorEvents.Blocks(this)::registerBlockColor);

modbus.addListener(new ColorEvents.Items(this)::registerItemColor);
modbus.addListener(this::addCreative);

Expand Down Expand Up @@ -165,10 +162,6 @@ public String getModId() {
return modId;
}

public BlockRegistry blockRegistry() {
return BlockRegistry.create(this);
}

public BlockEntityRegistry blockEntityRegistry() {
return BlockEntityRegistry.create(this);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/enderio/regilite/RegiliteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public final T get() {
return holder.value();
}

protected final ResourceLocation getId() {
@ApiStatus.Internal
public final ResourceLocation getId() {
return holder.getId();
}

Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/enderio/regilite/blocks/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import com.enderio.regilite.items.RegiliteItems;
import com.enderio.regilite.lang.RegiliteLang;
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.utils.DefaultTranslationUtility;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.registries.DeferredBlock;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

Expand All @@ -33,9 +33,14 @@ public final class BlockBuilder<T extends Block> extends RegiliteBuilder<BlockBu
private final RegiliteTags tagsModule;
private final RegiliteItems itemsModule;

private Supplier<String> descriptionIdSupplier = this::getDescriptionId;

@Nullable
private BiConsumer<RegiliteBlockLootProvider, T> lootTable = RegiliteBlockLootProvider::dropSelf;

@Nullable
private BiConsumer<BlockStateProvider, DataGenContext<Block, T>> blockStateProvider = (prov, ctx) -> prov.simpleBlock(ctx.get());

@Nullable
private Supplier<Supplier<BlockColor>> blockColorSupplier;

Expand All @@ -44,18 +49,23 @@ public BlockBuilder(DeferredBlock<T> holder, RegiliteLang langModule, RegiliteTa
this.langModule = langModule;
this.tagsModule = tagsModule;
this.itemsModule = itemsModule;

// Default translation
translation(DefaultTranslationUtility.getDefaultTranslationFrom(getId().getPath()));
}

public BlockBuilder<T> translation(String englishTranslation) {
langModule.add(this::getDescriptionId, englishTranslation);
langModule.add(descriptionIdSupplier, englishTranslation);
return this;
}

// Do not call directly, use descriptionIdSupplier
@Deprecated
private String getDescriptionId() {
return get().getDescriptionId();
}

public final BlockBuilder<T> tag(TagKey<Block> tag) {
public BlockBuilder<T> tag(TagKey<Block> tag) {
tagsModule.blocks().tag(tag).add(this::get);
return this;
}
Expand Down Expand Up @@ -96,7 +106,13 @@ public BiConsumer<RegiliteBlockLootProvider, T> lootTable() {
}

public BlockBuilder<T> blockStateProvider(BiConsumer<BlockStateProvider, DataGenContext<Block, T>> blockStateProvider) {
throw new NotImplementedException();
this.blockStateProvider = blockStateProvider;
return this;
}

@ApiStatus.Internal
public BiConsumer<BlockStateProvider, DataGenContext<Block, T>> blockStateProvider() {
return blockStateProvider;
}

public BlockBuilder<T> blockColor(@Nullable Supplier<Supplier<BlockColor>> colorSupplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import net.minecraft.core.HolderLookup;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Team Ender IO and contributors
* SPDX-License-Identifier: LGPL-3.0-only
*/

package com.enderio.regilite.blocks;

import com.enderio.regilite.data.DataGenContext;
import net.minecraft.data.PackOutput;
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;

public class RegiliteBlockStateProvider extends BlockStateProvider {
private final RegiliteBlocks blocks;

public RegiliteBlockStateProvider(PackOutput output, String modid, ExistingFileHelper exFileHelper, RegiliteBlocks blocks) {
super(output, modid, exFileHelper);
this.blocks = blocks;
}

@Override
protected void registerStatesAndModels() {
blocks.blockBuilders().forEach(this::registerState);
}

private <T extends Block> void registerState(BlockBuilder<T> blockBuilder) {
var blockStateProvider = blockBuilder.blockStateProvider();
if (blockStateProvider != null) {
blockStateProvider.accept(this, new DataGenContext<>(blockBuilder.getId(), blockBuilder::get));
}
}
}
21 changes: 17 additions & 4 deletions src/main/java/com/enderio/regilite/blocks/RegiliteBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.enderio.regilite.blocks;

import com.enderio.regilite.Regilite;
import com.enderio.regilite.RegiliteModuleDataGen;
import com.enderio.regilite.RegiliteModuleEvents;
import com.enderio.regilite.RegiliteRegistryModule;
import com.enderio.regilite.items.RegiliteItems;
Expand All @@ -16,22 +17,26 @@
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.DataProvider;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

public final class RegiliteBlocks implements RegiliteRegistryModule<Block, DeferredRegister.Blocks>, RegiliteModuleEvents {
public final class RegiliteBlocks implements RegiliteRegistryModule<Block, DeferredRegister.Blocks>, RegiliteModuleEvents, RegiliteModuleDataGen {
private final String modId;
private final RegiliteLang langModule;
private final RegiliteTags tagsModule;
private final RegiliteItems itemsModule;
Expand All @@ -43,7 +48,8 @@ public final class RegiliteBlocks implements RegiliteRegistryModule<Block, Defer
// TODO: Look into a way to drop this list, either by not having it or by dumping its contents once all events have fired?
private final ObjectList<BlockBuilder<? extends Block>> blocks = new ObjectArrayList<>();

public RegiliteBlocks(RegiliteLang langModule, RegiliteTags tagsModule, RegiliteItems itemsModule, RegiliteLootTables lootTablesModule, DeferredRegister.Blocks deferredRegister) {
public RegiliteBlocks(String modId, RegiliteLang langModule, RegiliteTags tagsModule, RegiliteItems itemsModule, RegiliteLootTables lootTablesModule, DeferredRegister.Blocks deferredRegister) {
this.modId = modId;
this.langModule = langModule;
this.tagsModule = tagsModule;
this.itemsModule = itemsModule;
Expand Down Expand Up @@ -73,7 +79,7 @@ public BlockBuilder<Block> createSimple(String name, BlockBehaviour.Properties p

@ApiStatus.Internal
public static RegiliteBlocks create(Regilite regilite) {
return new RegiliteBlocks(regilite.lang(), regilite.tags(), regilite.items(), regilite.lootTables(), DeferredRegister.createBlocks(regilite.getModId()));
return new RegiliteBlocks(regilite.getModId(), regilite.lang(), regilite.tags(), regilite.items(), regilite.lootTables(), DeferredRegister.createBlocks(regilite.getModId()));
}

@Override
Expand All @@ -98,5 +104,12 @@ public void register(IEventBus modEventBus) {
}
}

// TODO: Create data providers for loot tables, block states etc.
@Override
public void gatherProviders(GatherDataEvent event, Consumer<DataProvider> addProvider) {
if (!event.includeClient()) {
return;
}

addProvider.accept(new RegiliteBlockStateProvider(event.getGenerator().getPackOutput(), modId, event.getExistingFileHelper(), this));
}
}
Loading

0 comments on commit 6b8cc72

Please sign in to comment.