Skip to content

Commit

Permalink
Merge pull request #1 from Team-EnderIO/test-sourceset
Browse files Browse the repository at this point in the history
Split into main and test sourceset
  • Loading branch information
ferriarnus authored Jan 14, 2024
2 parents 0a211a0 + 9a17b95 commit d48ce58
Show file tree
Hide file tree
Showing 55 changed files with 482 additions and 249 deletions.
21 changes: 19 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ runs {
systemProperty 'forge.logging.console.level', 'debug'

modSource project.sourceSets.main
modSource project.sourceSets.test
}

client {
Expand All @@ -65,12 +66,28 @@ runs {
// workingDirectory project.file('run-data')

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
programArguments.addAll '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/test/resources/').getAbsolutePath()
}
}

sourceSets {
main {
java {}
}
test {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
}

sourceSets.test.runs {
modIdentifier = "examplemod"
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
sourceSets.test.resources { srcDir 'src/generated/resources' }


dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ loader_version_range=[1,)

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=examplemod
mod_id=regilite
# The human-readable display name for the mod.
mod_name=Example Mod
mod_name=Regilite
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import com.example.examplemod.registry.EnderBlockRegistry;
import com.example.examplemod.registry.EnderDeferredBlock;
import com.example.regilite.registry.EnderBlockRegistry;
import com.example.regilite.registry.EnderDeferredBlock;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootTable;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
Expand All @@ -31,9 +29,11 @@ public EnderBlockLootProvider(Set<Item> explosionResistant, EnderBlockRegistry r
@Override
protected void generate() {
for (DeferredHolder<Block, ? extends Block> block : registry.getEntries()) {
BiConsumer<EnderBlockLootProvider, Block> lootTable = ((EnderDeferredBlock<Block>) block).getLootTable();
if (lootTable != null) {
lootTable.accept(this, block.get());
if (block instanceof EnderDeferredBlock) {
BiConsumer<EnderBlockLootProvider, Block> lootTable = ((EnderDeferredBlock<Block>) block).getLootTable();
if (lootTable != null) {
lootTable.accept(this, block.get());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import com.example.examplemod.registry.EnderBlockRegistry;
import com.example.examplemod.registry.EnderDeferredBlock;
import com.example.regilite.registry.EnderBlockRegistry;
import com.example.regilite.registry.EnderDeferredBlock;
import net.minecraft.data.PackOutput;
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
Expand All @@ -21,9 +21,11 @@ public EnderBlockStateProvider(PackOutput output, String modid, ExistingFileHelp
@Override
protected void registerStatesAndModels() {
for (DeferredHolder<Block, ? extends Block> block : registry.getEntries()) {
BiConsumer<BlockStateProvider, Block> blockstate = ((EnderDeferredBlock<Block>) block).getBlockStateProvider();
if (blockstate != null) {
blockstate.accept(this, block.get());
if (block instanceof EnderDeferredBlock) {
BiConsumer<BlockStateProvider, Block> blockstate = ((EnderDeferredBlock<Block>) block).getBlockStateProvider();
if (blockstate != null) {
blockstate.accept(this, block.get());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import com.example.examplemod.testmod.ExampleMod;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import org.apache.commons.lang3.function.TriFunction;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = ExampleMod.MODID)
public class EnderDataProvider implements DataProvider {
private final String modid;
private final Map<Supplier<String>, String> langEntries = new HashMap<>();
private final List<DataProvider> subProviders = new ArrayList<>();
private final List<TriFunction<PackOutput, ExistingFileHelper, CompletableFuture<HolderLookup.Provider>, DataProvider>> serverSubProviderConsumers = new ArrayList<>();
private static final Map<String, EnderDataProvider> INSTANCES = new HashMap<>();
private boolean registered = false;

protected EnderDataProvider(String modid) {
this.modid = modid;
Expand All @@ -34,6 +35,15 @@ public static EnderDataProvider getInstance(String modid) {
return INSTANCES.computeIfAbsent(modid, EnderDataProvider::new);
}

public static EnderDataProvider register(String modid, IEventBus modbus) {
EnderDataProvider provider = INSTANCES.computeIfAbsent(modid, EnderDataProvider::new);
if (!provider.registered) {
modbus.addListener(provider::onGatherData);
provider.registered = true;
}
return provider;
}

public void addSubProvider(boolean include, DataProvider provider) {
if (include) {
subProviders.add(provider);
Expand Down Expand Up @@ -75,19 +85,15 @@ public String getName() {
return "Ender IO Data (" + modid + ")";
}

@SubscribeEvent
static void onGatherData(GatherDataEvent event) {
for (EnderDataProvider provider : INSTANCES.values()) {
if (event.includeServer()) {
for (TriFunction<PackOutput, ExistingFileHelper, CompletableFuture<HolderLookup.Provider>, DataProvider> function : provider.serverSubProviderConsumers) {
provider.subProviders.add(function.apply(event.getGenerator().getPackOutput(), event.getExistingFileHelper(), event.getLookupProvider()));
}
void onGatherData(GatherDataEvent event) {
if (event.includeServer()) {
for (TriFunction<PackOutput, ExistingFileHelper, CompletableFuture<HolderLookup.Provider>, DataProvider> function : this.serverSubProviderConsumers) {
this.subProviders.add(function.apply(event.getGenerator().getPackOutput(), event.getExistingFileHelper(), event.getLookupProvider()));
}
EnderLangProvider enUs = new EnderLangProvider(event.getGenerator().getPackOutput(), provider.modid, "en_us");
enUs.add(provider.langEntries);
provider.subProviders.add(enUs);
event.getGenerator().addProvider(true, provider);
}

EnderLangProvider enUs = new EnderLangProvider(event.getGenerator().getPackOutput(), this.modid, "en_us");
enUs.add(this.langEntries);
this.subProviders.add(enUs);
event.getGenerator().addProvider(true, this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import com.example.examplemod.registry.EnderDeferredItem;
import com.example.examplemod.registry.EnderItemRegistry;
import com.example.regilite.registry.EnderDeferredBlock;
import com.example.regilite.registry.EnderDeferredItem;
import com.example.regilite.registry.EnderItemRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -30,10 +31,13 @@ public EnderItemModelProvider(PackOutput output, String modid, ExistingFileHelpe
@Override
protected void registerModels() {
for (DeferredHolder<Item, ? extends Item> item : registry.getEntries()) {
BiConsumer<EnderItemModelProvider, Item> modelProvider = (BiConsumer<EnderItemModelProvider, Item>) ((EnderDeferredItem<? extends Item>) item).getModelProvider();
if (modelProvider != null) {
modelProvider.accept(this, item.get());
if (item instanceof EnderDeferredItem) {
BiConsumer<EnderItemModelProvider, Item> modelProvider = (BiConsumer<EnderItemModelProvider, Item>) ((EnderDeferredItem<? extends Item>) item).getModelProvider();
if (modelProvider != null) {
modelProvider.accept(this, item.get());
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import net.minecraft.data.PackOutput;
import net.neoforged.neoforge.common.data.LanguageProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.examplemod.data;
package com.example.regilite.data;

import com.example.examplemod.registry.ITagagble;
import com.example.regilite.registry.ITagagble;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.data.PackOutput;
Expand All @@ -27,8 +27,10 @@ public EnderTagProvider(PackOutput output, ResourceKey<? extends Registry<T>> ke
@Override
protected void addTags(HolderLookup.Provider p_256380_) {
for (DeferredHolder<T, ? extends T> entry : registry.getEntries()) {
Set<TagKey<T>> tag = ((ITagagble<T>) entry).getTags();
tag.forEach(t -> tag(t).add(entry.get()));
if (entry instanceof ITagagble) {
Set<TagKey<T>> tag = ((ITagagble<T>) entry).getTags();
tag.forEach(t -> tag(t).add(entry.get()));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.examplemod.events;
package com.example.regilite.events;

import com.example.examplemod.registry.EnderBlockEntityRegistry;
import com.example.examplemod.registry.EnderDeferredBlockEntity;
import com.example.regilite.registry.EnderBlockEntityRegistry;
import com.example.regilite.registry.EnderDeferredBlockEntity;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -20,9 +20,12 @@ public BlockEntityRendererEvents(EnderBlockEntityRegistry registry) {

private <T extends BlockEntity> void registerGenericBER(EntityRenderersEvent.RegisterRenderers event) {
for (DeferredHolder<BlockEntityType<?>, ? extends BlockEntityType<?>> be : registry.getEntries()) {
Supplier<BlockEntityRendererProvider<T>> renderer = ((EnderDeferredBlockEntity<T>) be).getRenderer();
if (renderer != null)
event.registerBlockEntityRenderer(((EnderDeferredBlockEntity<T>) be).get(), renderer.get());
if (be instanceof EnderDeferredBlockEntity) {
Supplier<BlockEntityRendererProvider<T>> renderer = ((EnderDeferredBlockEntity<T>) be).getRenderer();
if (renderer != null)
event.registerBlockEntityRenderer(((EnderDeferredBlockEntity<T>) be).get(), renderer.get());

}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.example.examplemod.events;
package com.example.regilite.events;

import com.example.examplemod.registry.EnderBlockRegistry;
import com.example.examplemod.registry.EnderDeferredBlock;
import com.example.examplemod.registry.EnderDeferredItem;
import com.example.examplemod.registry.EnderItemRegistry;
import com.example.regilite.registry.*;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.neoforged.bus.api.Event;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.registries.DeferredHolder;

import javax.annotation.Nullable;
import java.util.function.Supplier;

public class ColorEvents {
Expand All @@ -26,9 +21,11 @@ public Items(EnderItemRegistry items) {

public void registerItemColor(RegisterColorHandlersEvent.Item event) {
for (DeferredHolder<Item, ? extends Item> item : items.getEntries()) {
Supplier<ItemColor> colorSupplier = ((EnderDeferredItem<Item>) item).getColorSupplier();
if (colorSupplier != null)
event.register(colorSupplier.get(), item.get());
if (item instanceof EnderDeferredItem) {
IItemColor colorSupplier = ((EnderDeferredItem<Item>) item).getColorSupplier();
if (colorSupplier != null)
event.register(colorSupplier::getColor, item.get());
}
}
}
}
Expand All @@ -42,9 +39,11 @@ public Blocks(EnderBlockRegistry blocks) {

public void registerBlockColor(RegisterColorHandlersEvent.Block event) {
for (DeferredHolder<Block, ? extends Block> block : blocks.getEntries()) {
Supplier<BlockColor> colorSupplier = ((EnderDeferredBlock<Block>) block).getColorSupplier();
if (colorSupplier != null)
event.register(colorSupplier.get(), block.get());
if (block instanceof EnderDeferredBlock) {
IBlockColor colorSupplier = ((EnderDeferredBlock<Block>) block).getColorSupplier();
if (colorSupplier != null)
event.register(colorSupplier::getColor, block.get());
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/example/regilite/events/IBlockColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.regilite.events;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;

public interface IBlockColor {
int getColor(BlockState state, @Nullable BlockAndTintGetter getter, @Nullable BlockPos pos, int layer);
}
7 changes: 7 additions & 0 deletions src/main/java/com/example/regilite/events/IItemColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.regilite.events;

import net.minecraft.world.item.ItemStack;

public interface IItemColor {
int getColor(ItemStack stack, int layer);
}
Loading

0 comments on commit d48ce58

Please sign in to comment.