ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/data/ItemModelGenerator.java

106 lines
4.8 KiB
Java
Raw Normal View History

2021-11-24 01:17:37 +01:00
package de.ellpeck.actuallyadditions.data;
2022-01-09 00:10:34 +01:00
import com.google.common.collect.ImmutableSet;
2021-11-24 01:17:37 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
2022-01-05 18:31:40 +01:00
import de.ellpeck.actuallyadditions.mod.fluids.FluidAA;
2021-12-30 18:30:01 +01:00
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
2021-11-24 17:57:31 +01:00
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
2024-03-04 20:21:48 +01:00
import net.minecraft.core.registries.BuiltInRegistries;
2024-03-03 01:20:53 +01:00
import net.minecraft.data.PackOutput;
2024-03-02 21:23:08 +01:00
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WallBlock;
2024-03-04 20:21:48 +01:00
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
import net.neoforged.neoforge.client.model.generators.ModelFile;
import net.neoforged.neoforge.client.model.generators.loaders.DynamicFluidContainerModelBuilder;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.registries.DeferredHolder;
2021-11-24 01:17:37 +01:00
2022-01-09 00:10:34 +01:00
import java.util.Set;
2021-11-24 01:17:37 +01:00
import java.util.function.Supplier;
public class ItemModelGenerator extends ItemModelProvider {
2024-03-03 01:20:53 +01:00
public ItemModelGenerator(PackOutput packOutput, ExistingFileHelper existingFileHelper) {
super(packOutput, ActuallyAdditions.MODID, existingFileHelper);
2021-11-24 01:17:37 +01:00
}
@Override
protected void registerModels() {
// Items
2024-03-09 22:16:34 +01:00
simpleTool(ActuallyItems.ITEM_BOOKLET); // will require complex I think
simpleTool(ActuallyItems.CRATE_KEEPER);
2021-11-24 01:17:37 +01:00
// All items?
2021-11-24 17:57:31 +01:00
ActuallyItems.SIMPLE_ITEMS.forEach(this::simpleItem);
2024-03-09 22:16:34 +01:00
ActuallyItems.TOOLS.forEach(this::simpleTool);
2021-11-24 01:17:37 +01:00
// Toolsets
/* ActuallyItems.ALL_TOOL_SETS.stream()
.map(ToolSet::getItemGroup)
.flatMap(Collection::stream)
.forEach(item -> simpleItem(() -> item));*/
2022-01-09 00:10:34 +01:00
Set<Block> ignoreList = ImmutableSet.of(
InitFluids.CANOLA_OIL.getBlock(),
InitFluids.REFINED_CANOLA_OIL.getBlock(),
InitFluids.CRYSTALLIZED_OIL.getBlock(),
2022-01-09 00:10:34 +01:00
InitFluids.EMPOWERED_OIL.getBlock(),
ActuallyBlocks.CANOLA.get(),
ActuallyBlocks.RICE.get(),
ActuallyBlocks.FLAX.get(),
2024-03-03 20:52:31 +01:00
ActuallyBlocks.COFFEE.get(),
ActuallyBlocks.TINY_TORCH.get()
2022-01-09 00:10:34 +01:00
);
2021-11-24 01:17:37 +01:00
// Blocks
2022-01-09 00:10:34 +01:00
ActuallyBlocks.BLOCKS.getEntries().stream().filter(b -> !ignoreList.contains(b.get())).forEach(this::registerBlockModel);
2021-12-30 18:30:01 +01:00
2022-01-05 18:31:40 +01:00
generateBucket(InitFluids.CANOLA_OIL);
generateBucket(InitFluids.REFINED_CANOLA_OIL);
generateBucket(InitFluids.CRYSTALLIZED_OIL);
2022-01-05 18:31:40 +01:00
generateBucket(InitFluids.EMPOWERED_OIL);
2023-01-16 22:47:31 +01:00
2024-03-03 01:20:53 +01:00
String wormpath = ActuallyItems.WORM.getId().getPath();
2023-01-16 22:47:31 +01:00
singleTexture(wormpath, mcLoc("item/handheld"), "layer0", modLoc("item/" + wormpath))
.override().predicate(new ResourceLocation(ActuallyAdditions.MODID, "snail"), 1F)
.model(singleTexture("snail", mcLoc("item/handheld"), "layer0", modLoc("item/snail"))).end();
/* withExistingParent(wormpath, mcLoc("item/handheld"))
.texture("layer0", modLoc("item/" + wormpath))
.override().predicate(new ResourceLocation(ActuallyAdditions.MODID, "snail"), 1F)
.model(getBuilder("snail").parent(getExistingFile(mcLoc("item/handheld"))).texture("layer0", "item/snail")).end();*/
2024-03-03 20:52:31 +01:00
2024-03-04 20:21:48 +01:00
String torchPath = BuiltInRegistries.ITEM.getKey(ActuallyBlocks.TINY_TORCH.getItem()).getPath();
2024-03-03 20:52:31 +01:00
singleTexture(torchPath, mcLoc("item/generated"), "layer0", modLoc("block/" + torchPath));
2022-01-05 18:31:40 +01:00
}
private void generateBucket(FluidAA fluidSupplier) {
2024-03-04 22:42:35 +01:00
withExistingParent(BuiltInRegistries.ITEM.getKey(fluidSupplier.getBucket()).getPath(), "neoforge:item/bucket")
2024-03-03 01:20:53 +01:00
.customLoader((builder, template) -> DynamicFluidContainerModelBuilder.begin(builder, template).fluid(fluidSupplier.get()));
2021-11-24 01:17:37 +01:00
}
2024-03-04 20:21:48 +01:00
private void registerBlockModel(DeferredHolder<Block, ? extends Block> block) {
2024-03-03 01:20:53 +01:00
String path = block.getId().getPath();
2021-11-24 01:17:37 +01:00
if (block.get() instanceof WallBlock) {
String name = path;
2021-11-26 00:51:59 +01:00
path = "block/" + path.replace("_wall", "_block");
2021-11-24 01:17:37 +01:00
withExistingParent(name, new ResourceLocation("block/wall_inventory"))
.texture("wall", modLoc(path));
return;
}
2021-11-26 00:51:59 +01:00
getBuilder(path).parent(new ModelFile.UncheckedModelFile(modLoc("block/" + path)));
2021-11-24 01:17:37 +01:00
}
2024-03-09 22:16:34 +01:00
private void simpleTool(Supplier<? extends Item> item) {
2024-03-04 20:21:48 +01:00
String path = BuiltInRegistries.ITEM.getKey(item.get()).getPath();
2021-11-24 01:17:37 +01:00
singleTexture(path, mcLoc("item/handheld"), "layer0", modLoc("item/" + path));
}
2024-03-09 22:16:34 +01:00
private void simpleItem(Supplier<? extends Item> item) {
String path = BuiltInRegistries.ITEM.getKey(item.get()).getPath();
singleTexture(path, mcLoc("item/generated"), "layer0", modLoc("item/" + path));
}
2021-11-24 01:17:37 +01:00
}