|
| 1 | +package com.gregtechceu.gtstoragedrawers.data; |
| 2 | + |
| 3 | +import com.gregtechceu.gtstoragedrawers.DrawerTypes; |
| 4 | +import com.gregtechceu.gtstoragedrawers.GregTechStorageDrawers; |
| 5 | + |
| 6 | +import net.minecraft.core.Direction; |
| 7 | +import net.minecraft.data.PackOutput; |
| 8 | +import net.minecraft.resources.ResourceLocation; |
| 9 | +import net.minecraftforge.client.model.generators.BlockModelBuilder; |
| 10 | +import net.minecraftforge.client.model.generators.BlockStateProvider; |
| 11 | +import net.minecraftforge.client.model.generators.ConfiguredModel; |
| 12 | +import net.minecraftforge.client.model.generators.ModelFile; |
| 13 | +import net.minecraftforge.client.model.generators.VariantBlockStateBuilder; |
| 14 | +import net.minecraftforge.common.data.ExistingFileHelper; |
| 15 | + |
| 16 | +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; |
| 17 | +import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers; |
| 18 | +import com.jaquadro.minecraft.storagedrawers.block.BlockStandardDrawers; |
| 19 | + |
| 20 | +public class ModBlockStateProvider extends BlockStateProvider { |
| 21 | + |
| 22 | + public ModBlockStateProvider(PackOutput output, ExistingFileHelper helper) { |
| 23 | + super(output, GregTechStorageDrawers.MODID, helper); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + protected void registerStatesAndModels() { |
| 28 | + for (DrawerTypes type : DrawerTypes.values()) { |
| 29 | + registerType(type); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + void registerType(DrawerTypes type) { |
| 34 | + BlockModelBuilder blockTrim = models().cubeAll(type.getTrimModelName(), modLoc(type.getTextureName("side"))); |
| 35 | + simpleBlock(type.getData().blockTrim.get(), blockTrim); |
| 36 | + |
| 37 | + standardDrawer(type, type.getData().blockFull1.get(), |
| 38 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 39 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_1")), |
| 40 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 41 | + 1, false); |
| 42 | + standardDrawer(type, type.getData().blockFull2.get(), |
| 43 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 44 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_2")), |
| 45 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 46 | + 2, false); |
| 47 | + standardDrawer(type, type.getData().blockFull4.get(), |
| 48 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 49 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_4")), |
| 50 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 51 | + 4, false); |
| 52 | + |
| 53 | + standardDrawer(type, type.getData().blockHalf1.get(), |
| 54 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 55 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_1")), |
| 56 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side_h")), |
| 57 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 58 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 59 | + 1, true); |
| 60 | + standardDrawer(type, type.getData().blockHalf2.get(), |
| 61 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 62 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_2")), |
| 63 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side_h")), |
| 64 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 65 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 66 | + 2, true); |
| 67 | + standardDrawer(type, type.getData().blockHalf4.get(), |
| 68 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 69 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("front_4")), |
| 70 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side_h")), |
| 71 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("side")), |
| 72 | + new ResourceLocation(GregTechStorageDrawers.MODID, type.getTextureName("trim")), |
| 73 | + 4, true); |
| 74 | + } |
| 75 | + |
| 76 | + void standardDrawer(DrawerTypes type, BlockStandardDrawers block, ResourceLocation side, ResourceLocation front, |
| 77 | + ResourceLocation trim, int size, boolean half) { |
| 78 | + standardDrawer(type, block, side, front, side, side, trim, size, half); |
| 79 | + } |
| 80 | + |
| 81 | + void standardDrawer(DrawerTypes type, BlockStandardDrawers block, ResourceLocation side, ResourceLocation front, |
| 82 | + ResourceLocation top, ResourceLocation back, ResourceLocation trim, int size, boolean half) { |
| 83 | + String parentType = half ? "half" : "full"; |
| 84 | + ResourceLocation parent = new ResourceLocation(StorageDrawers.MOD_ID, |
| 85 | + "block/" + parentType + "_drawers_orientable"); |
| 86 | + |
| 87 | + ModelFile model = models() |
| 88 | + .withExistingParent(type.getDrawerModelName(size, half), parent) |
| 89 | + .texture("particle", front) |
| 90 | + .texture("east", side) |
| 91 | + .texture("west", side) |
| 92 | + .texture("north", front) |
| 93 | + .texture("up", top) |
| 94 | + .texture("down", top) |
| 95 | + .texture("south", back) |
| 96 | + .texture("trim", trim); |
| 97 | + |
| 98 | + drawerState(block, model); |
| 99 | + } |
| 100 | + |
| 101 | + void drawerState(BlockStandardDrawers block, ModelFile model) { |
| 102 | + VariantBlockStateBuilder builder = getVariantBuilder(block); |
| 103 | + builder.partialState().with(BlockDrawers.FACING, Direction.NORTH).addModels(new ConfiguredModel(model)); |
| 104 | + builder.partialState().with(BlockDrawers.FACING, Direction.EAST) |
| 105 | + .addModels(new ConfiguredModel(model, 0, 90, false)); |
| 106 | + builder.partialState().with(BlockDrawers.FACING, Direction.SOUTH) |
| 107 | + .addModels(new ConfiguredModel(model, 0, 180, false)); |
| 108 | + builder.partialState().with(BlockDrawers.FACING, Direction.WEST) |
| 109 | + .addModels(new ConfiguredModel(model, 0, 270, false)); |
| 110 | + } |
| 111 | +} |
0 commit comments