/
BlockStateProviderUpgC.java
198 lines (169 loc) · 9.26 KB
/
BlockStateProviderUpgC.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.nik7.upgradecraft.datagenerators;
import com.nik7.upgradecraft.blocks.FluidFurnaceBlock;
import com.nik7.upgradecraft.blocks.FunnelBlock;
import com.nik7.upgradecraft.init.RegisterBlocks;
import com.nik7.upgradecraft.state.properties.TankType;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.client.model.generators.VariantBlockStateBuilder.PartialBlockstate;
import net.minecraftforge.common.data.ExistingFileHelper;
import javax.annotation.Nullable;
import static com.nik7.upgradecraft.UpgradeCraft.MOD_ID;
import static com.nik7.upgradecraft.blocks.AbstractFluidTankBlock.MIXED;
import static com.nik7.upgradecraft.blocks.FunnelBlock.ENABLED;
import static com.nik7.upgradecraft.blocks.WoodenFluidTankBlock.TYPE;
public class BlockStateProviderUpgC extends BlockStateProvider {
public BlockStateProviderUpgC(DataGenerator gen, ExistingFileHelper exFileHelper) {
super(gen, MOD_ID, exFileHelper);
}
@Override
protected void registerStatesAndModels() {
simpleBlock(RegisterBlocks.SLIMY_PLANKS_BLOCK.get(),
models().cubeAll("slimy_planks_block", new ResourceLocation(MOD_ID, "block/slimy_planks_block")));
createTankModel(RegisterBlocks.WOODEN_FLUID_TANK_BLOCK.get(),
"wooden_fluid_tank",
"double_wooden_fluid_tank");
createTankModel(RegisterBlocks.WOODEN_FLUID_TANK_GLASSED_BLOCK.get(),
"wooden_fluid_tank_glassed",
"double_wooden_fluid_tank_glassed_up",
"double_wooden_fluid_tank_glassed_down",
"double_wooden_fluid_tank_glassed_mixed"
);
createFunnel(RegisterBlocks.FUNNEL_BLOCK.get(), "funnel");
createOrientableMachine(RegisterBlocks.FLUID_FURNACE_BLOCK.get(), "furnace_machine", "fluid_furnace");
createOrientableMachine(RegisterBlocks.FLUID_INFUSER_BLOCK.get(), "fluid_infuser", "fluid_infuser");
createTankModel(RegisterBlocks.CLAY_FLUID_TANK_BLOCK.get(),
"clay_fluid_tank",
"double_clay_fluid_tank");
createTankModel(RegisterBlocks.CLAY_FLUID_TANK_GLASSED_BLOCK.get(),
"clay_fluid_tank_glassed",
"double_clay_fluid_tank_glassed_up",
"double_clay_fluid_tank_glassed_down",
"double_clay_fluid_tank_glassed_mixed"
);
createTankModel(RegisterBlocks.TERRACOTTA_FLUID_TANK_BLOCK.get(),
"terracotta_fluid_tank",
"double_terracotta_fluid_tank");
createTankModel(RegisterBlocks.TERRACOTTA_FLUID_TANK_GLASSED_BLOCK.get(),
"terracotta_fluid_tank_glassed",
"double_terracotta_fluid_tank_glassed_up",
"double_terracotta_fluid_tank_glassed_down",
"double_terracotta_fluid_tank_glassed_mixed"
);
simpleBlock(RegisterBlocks.CLAY_BRICKS_BLOCK.get(),
models().cubeAll("clay_bricks_block", new ResourceLocation(MOD_ID, "block/clay_bricks_block")));
slabBlock(RegisterBlocks.CLAY_BRICKS_SLAB_BLOCK.get(), new ResourceLocation(MOD_ID, "block/clay_bricks_block"),
new ResourceLocation(MOD_ID, "block/clay_bricks_block"));
wallBlock(RegisterBlocks.CLAY_BRICKS_WALL_BLOCK.get(), new ResourceLocation(MOD_ID, "block/clay_bricks_block"));
stairsBlock(RegisterBlocks.CLAY_BRICKS_STAIRS_BLOCK.get(), new ResourceLocation(MOD_ID, "block/clay_bricks_block"));
}
private void createOrientableMachine(Block block, String modelName, String texture) {
PartialBlockstate partialBlockstate = null;
for (Direction direction : Direction.Plane.HORIZONTAL) {
if (partialBlockstate == null) {
partialBlockstate = getVariantBuilder(block).partialState();
} else {
partialBlockstate = partialBlockstate.partialState();
}
partialBlockstate = partialBlockstate
.with(FluidFurnaceBlock.FACING, direction).with(FluidFurnaceBlock.LIT, false)
.addModels(createOrientableMachineModels(modelName, texture, direction, false));
partialBlockstate = partialBlockstate.partialState()
.with(FluidFurnaceBlock.FACING, direction).with(FluidFurnaceBlock.LIT, true)
.addModels(createOrientableMachineModels(modelName, texture, direction, true));
}
}
private ConfiguredModel[] createOrientableMachineModels(String modelName, String texture, Direction facing, boolean lit) {
String active = lit ? "_on" : "_off";
ModelFile model = models()
.withExistingParent(texture + "_" + facing.name().toLowerCase() + active, modLoc("block/" + modelName))
.texture("all", modLoc("block/" + texture))
.texture("in", modLoc("block/" + texture + active));
return ConfiguredModel.builder()
.modelFile(model)
.rotationY((int) (facing.getHorizontalAngle() + 180) % 360)
.build();
}
private void createFunnel(Block block, String texture) {
getVariantBuilder(block).forAllStatesExcept(state -> {
Direction facing = state.get(FunnelBlock.FACING);
String modelName;
int rotationY;
if (facing == Direction.DOWN) {
modelName = "funnel";
rotationY = 0;
} else {
modelName = "funnel_side";
rotationY = (int) (facing.getHorizontalAngle() + 180) % 360;
}
ModelFile model = models()
.withExistingParent(texture + "_" + facing.name().toLowerCase(), modLoc("block/" + modelName))
.texture("all", modLoc("block/" + texture));
return ConfiguredModel.builder()
.modelFile(model)
.rotationY(rotationY)
.build();
}, ENABLED);
}
private void createTankModel(Block block,
String singleTexture,
String doubleTexture) {
createTankModel(block, singleTexture, doubleTexture, doubleTexture, null);
}
private void createTankModel(Block block,
String singleTexture,
String doubleTopTexture,
String doubleBottomTexture,
@Nullable String doubleMixedTexture) {
String topName;
String bottomName;
if (doubleTopTexture.equalsIgnoreCase(doubleBottomTexture)) {
topName = doubleTopTexture + "_top";
bottomName = doubleBottomTexture + "_bottom";
} else {
topName = doubleTopTexture;
bottomName = doubleBottomTexture;
}
PartialBlockstate partialBlockstate = getVariantBuilder(block)
.partialState().with(TYPE, TankType.SINGLE).addModels(ConfiguredModel.builder().modelFile(
models().withExistingParent(singleTexture, modLoc("block/fluid_tank"))
.texture("all", modLoc("block/" + singleTexture))
).build())
.partialState().with(TYPE, TankType.BOTTOM);
if (doubleMixedTexture != null) {
partialBlockstate = partialBlockstate.with(MIXED, false);
}
partialBlockstate = partialBlockstate.addModels(
ConfiguredModel.builder().modelFile(
models().withExistingParent(bottomName, modLoc("block/double_fluid_tank_down"))
.texture("all", modLoc("block/" + doubleBottomTexture))
).build())
.partialState().with(TYPE, TankType.TOP);
if (doubleMixedTexture != null) {
partialBlockstate = partialBlockstate.with(MIXED, false);
}
partialBlockstate = partialBlockstate.addModels(
ConfiguredModel.builder().modelFile(
models().withExistingParent(topName, modLoc("block/double_fluid_tank_up"))
.texture("all", modLoc("block/" + doubleTopTexture))
).build());
if (doubleMixedTexture != null) {
partialBlockstate
.partialState().with(TYPE, TankType.BOTTOM).with(MIXED, true).addModels(
ConfiguredModel.builder().modelFile(
models().withExistingParent(doubleMixedTexture + "_bottom", modLoc("block/double_fluid_tank_down"))
.texture("all", modLoc("block/" + doubleMixedTexture))
).build())
.partialState().with(TYPE, TankType.TOP).with(MIXED, true).addModels(
ConfiguredModel.builder().modelFile(
models().withExistingParent(doubleMixedTexture + "_top", modLoc("block/double_fluid_tank_up"))
.texture("all", modLoc("block/" + doubleMixedTexture))
).build());
}
}
}