Refactor BlockStateProvider to encapsulate a BlockModelProvider

Make most protected methods of data generators public
This commit is contained in:
tterrag committed 2020-01-05 14:27:20 -05:00
1 parent 3096608d4a
commit bc878ddf19
6 files changed
+207 -177

No files matched your search

@@ -56,6 +56,7 @@ import net.minecraft.block.StairsBlock;
import net.minecraft.block.TrapDoorBlock;
import net.minecraft.block.WallBlock;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IDataProvider;
import net.minecraft.state.properties.AttachFace;
import net.minecraft.state.properties.BlockStateProperties;
@@ -72,30 +73,47 @@ import net.minecraft.util.ResourceLocation;
* Data provider for blockstate files. Extends {@link BlockModelProvider} so that
* blockstates and their referenced models can be provided in tandem.
*/
public abstract class BlockStateProvider extends BlockModelProvider {
public abstract class BlockStateProvider implements IDataProvider {
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
@VisibleForTesting
protected final Map<Block, IGeneratedBlockstate> registeredBlocks = new LinkedHashMap<>();
private final DataGenerator generator;
private final String modid;
private final BlockModelProvider blockModels;
public BlockStateProvider(DataGenerator gen, String modid, ExistingFileHelper exFileHelper) {
super(gen, modid, exFileHelper);
this.generator = gen;
this.modid = modid;
this.blockModels = new BlockModelProvider(gen, modid, exFileHelper) {
@Override
public String getName() {
return BlockStateProvider.this.getName();
}
@Override
protected void registerModels() {}
};
}
@Override
protected final void registerModels() {
public void act(DirectoryCache cache) throws IOException {
models().clear();
registeredBlocks.clear();
registerStatesAndModels();
models().generateAll(cache);
for (Map.Entry<Block, IGeneratedBlockstate> entry : registeredBlocks.entrySet()) {
saveBlockState(entry.getValue().toJson(), entry.getKey());
saveBlockState(cache, entry.getValue().toJson(), entry.getKey());
}
}
protected abstract void registerStatesAndModels();
protected VariantBlockStateBuilder getVariantBuilder(Block b) {
public VariantBlockStateBuilder getVariantBuilder(Block b) {
if (registeredBlocks.containsKey(b)) {
IGeneratedBlockstate old = registeredBlocks.get(b);
Preconditions.checkState(old instanceof VariantBlockStateBuilder);
@@ -107,7 +125,7 @@ public abstract class BlockStateProvider extends BlockModelProvider {
}
}
protected MultiPartBlockStateBuilder getMultipartBuilder(Block b) {
public MultiPartBlockStateBuilder getMultipartBuilder(Block b) {
if (registeredBlocks.containsKey(b)) {
IGeneratedBlockstate old = registeredBlocks.get(b);
Preconditions.checkState(old instanceof MultiPartBlockStateBuilder);
@@ -118,58 +136,70 @@ public abstract class BlockStateProvider extends BlockModelProvider {
return ret;
}
}
public BlockModelProvider models() {
return blockModels;
}
public ResourceLocation modLoc(String name) {
return new ResourceLocation(modid, name);
}
public ResourceLocation mcLoc(String name) {
return new ResourceLocation(name);
}
private String name(Block block) {
return block.getRegistryName().getPath();
}
protected ResourceLocation blockTexture(Block block) {
public ResourceLocation blockTexture(Block block) {
ResourceLocation name = block.getRegistryName();
return new ResourceLocation(name.getNamespace(), BLOCK_FOLDER + "/" + name.getPath());
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
}
private ResourceLocation extend(ResourceLocation rl, String suffix) {
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
}
protected ModelFile cubeAll(Block block) {
return cubeAll(name(block), blockTexture(block));
public ModelFile cubeAll(Block block) {
return models().cubeAll(name(block), blockTexture(block));
}
protected void simpleBlock(Block block) {
public void simpleBlock(Block block) {
simpleBlock(block, cubeAll(block));
}
protected void simpleBlock(Block block, Function<ModelFile, ConfiguredModel[]> expander) {
public void simpleBlock(Block block, Function<ModelFile, ConfiguredModel[]> expander) {
simpleBlock(block, expander.apply(cubeAll(block)));
}
protected void simpleBlock(Block block, ModelFile model) {
public void simpleBlock(Block block, ModelFile model) {
simpleBlock(block, new ConfiguredModel(model));
}
protected void simpleBlock(Block block, ConfiguredModel... models) {
public void simpleBlock(Block block, ConfiguredModel... models) {
getVariantBuilder(block)
.partialState().setModels(models);
}
protected void axisBlock(RotatedPillarBlock block) {
public void axisBlock(RotatedPillarBlock block) {
axisBlock(block, blockTexture(block));
}
protected void logBlock(LogBlock block) {
public void logBlock(LogBlock block) {
axisBlock(block, blockTexture(block), extend(blockTexture(block), "_top"));
}
protected void axisBlock(RotatedPillarBlock block, ResourceLocation baseName) {
public void axisBlock(RotatedPillarBlock block, ResourceLocation baseName) {
axisBlock(block, extend(baseName, "_side"), extend(baseName, "_end"));
}
protected void axisBlock(RotatedPillarBlock block, ResourceLocation side, ResourceLocation end) {
axisBlock(block, cubeColumn(name(block), side, end));
public void axisBlock(RotatedPillarBlock block, ResourceLocation side, ResourceLocation end) {
axisBlock(block, models().cubeColumn(name(block), side, end));
}
protected void axisBlock(RotatedPillarBlock block, ModelFile model) {
public void axisBlock(RotatedPillarBlock block, ModelFile model) {
getVariantBuilder(block)
.partialState().with(RotatedPillarBlock.AXIS, Axis.Y)
.modelForState().modelFile(model).addModel()
@@ -181,23 +211,23 @@ public abstract class BlockStateProvider extends BlockModelProvider {
private static final int DEFAULT_ANGLE_OFFSET = 180;
protected void horizontalBlock(Block block, ResourceLocation side, ResourceLocation front, ResourceLocation top) {
horizontalBlock(block, orientable(name(block), side, front, top));
public void horizontalBlock(Block block, ResourceLocation side, ResourceLocation front, ResourceLocation top) {
horizontalBlock(block, models().orientable(name(block), side, front, top));
}
protected void horizontalBlock(Block block, ModelFile model) {
public void horizontalBlock(Block block, ModelFile model) {
horizontalBlock(block, model, DEFAULT_ANGLE_OFFSET);
}
protected void horizontalBlock(Block block, ModelFile model, int angleOffset) {
public void horizontalBlock(Block block, ModelFile model, int angleOffset) {
horizontalBlock(block, $ -> model, angleOffset);
}
protected void horizontalBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
public void horizontalBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
horizontalBlock(block, modelFunc, DEFAULT_ANGLE_OFFSET);
}
protected void horizontalBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
public void horizontalBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
getVariantBuilder(block)
.forAllStates(state -> ConfiguredModel.builder()
.modelFile(modelFunc.apply(state))
@@ -206,19 +236,19 @@ public abstract class BlockStateProvider extends BlockModelProvider {
);
}
protected void horizontalFaceBlock(Block block, ModelFile model) {
public void horizontalFaceBlock(Block block, ModelFile model) {
horizontalFaceBlock(block, model, DEFAULT_ANGLE_OFFSET);
}
protected void horizontalFaceBlock(Block block, ModelFile model, int angleOffset) {
public void horizontalFaceBlock(Block block, ModelFile model, int angleOffset) {
horizontalFaceBlock(block, $ -> model, angleOffset);
}
protected void horizontalFaceBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
public void horizontalFaceBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
horizontalBlock(block, modelFunc, DEFAULT_ANGLE_OFFSET);
}
protected void horizontalFaceBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
public void horizontalFaceBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
getVariantBuilder(block)
.forAllStates(state -> ConfiguredModel.builder()
.modelFile(modelFunc.apply(state))
@@ -228,19 +258,19 @@ public abstract class BlockStateProvider extends BlockModelProvider {
);
}
protected void directionalBlock(Block block, ModelFile model) {
public void directionalBlock(Block block, ModelFile model) {
directionalBlock(block, model, DEFAULT_ANGLE_OFFSET);
}
protected void directionalBlock(Block block, ModelFile model, int angleOffset) {
public void directionalBlock(Block block, ModelFile model, int angleOffset) {
directionalBlock(block, $ -> model, angleOffset);
}
protected void directionalBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
public void directionalBlock(Block block, Function<BlockState, ModelFile> modelFunc) {
directionalBlock(block, modelFunc, DEFAULT_ANGLE_OFFSET);
}
protected void directionalBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
public void directionalBlock(Block block, Function<BlockState, ModelFile> modelFunc, int angleOffset) {
getVariantBuilder(block)
.forAllStates(state -> {
Direction dir = state.get(BlockStateProperties.FACING);
@@ -252,30 +282,30 @@ public abstract class BlockStateProvider extends BlockModelProvider {
});
}
protected void stairsBlock(StairsBlock block, ResourceLocation texture) {
public void stairsBlock(StairsBlock block, ResourceLocation texture) {
stairsBlock(block, texture, texture, texture);
}
protected void stairsBlock(StairsBlock block, String name, ResourceLocation texture) {
public void stairsBlock(StairsBlock block, String name, ResourceLocation texture) {
stairsBlock(block, name, texture, texture, texture);
}
protected void stairsBlock(StairsBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public void stairsBlock(StairsBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
stairsBlockInternal(block, block.getRegistryName().toString(), side, bottom, top);
}
protected void stairsBlock(StairsBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public void stairsBlock(StairsBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
stairsBlockInternal(block, name + "_stairs", side, bottom, top);
}
private void stairsBlockInternal(StairsBlock block, String baseName, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
ModelFile stairs = stairs(baseName, side, bottom, top);
ModelFile stairsInner = stairsInner(baseName + "_inner", side, bottom, top);
ModelFile stairsOuter = stairsOuter(baseName + "_outer", side, bottom, top);
ModelFile stairs = models().stairs(baseName, side, bottom, top);
ModelFile stairsInner = models().stairsInner(baseName + "_inner", side, bottom, top);
ModelFile stairsOuter = models().stairsOuter(baseName + "_outer", side, bottom, top);
stairsBlock(block, stairs, stairsInner, stairsOuter);
}
protected void stairsBlock(StairsBlock block, ModelFile stairs, ModelFile stairsInner, ModelFile stairsOuter) {
public void stairsBlock(StairsBlock block, ModelFile stairs, ModelFile stairsInner, ModelFile stairsOuter) {
getVariantBuilder(block)
.forAllStatesExcept(state -> {
Direction facing = state.get(StairsBlock.FACING);
@@ -299,28 +329,28 @@ public abstract class BlockStateProvider extends BlockModelProvider {
}, StairsBlock.WATERLOGGED);
}
protected void slabBlock(SlabBlock block, ResourceLocation doubleslab, ResourceLocation texture) {
public void slabBlock(SlabBlock block, ResourceLocation doubleslab, ResourceLocation texture) {
slabBlock(block, doubleslab, texture, texture, texture);
}
protected void slabBlock(SlabBlock block, ResourceLocation doubleslab, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
slabBlock(block, slab(name(block), side, bottom, top), slabTop(name(block) + "_top", side, bottom, top), getExistingFile(doubleslab));
public void slabBlock(SlabBlock block, ResourceLocation doubleslab, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
slabBlock(block, models().slab(name(block), side, bottom, top), models().slabTop(name(block) + "_top", side, bottom, top), models().getExistingFile(doubleslab));
}
protected void slabBlock(SlabBlock block, ModelFile bottom, ModelFile top, ModelFile doubleslab) {
public void slabBlock(SlabBlock block, ModelFile bottom, ModelFile top, ModelFile doubleslab) {
getVariantBuilder(block)
.partialState().with(SlabBlock.TYPE, SlabType.BOTTOM).addModels(new ConfiguredModel(bottom))
.partialState().with(SlabBlock.TYPE, SlabType.TOP).addModels(new ConfiguredModel(top))
.partialState().with(SlabBlock.TYPE, SlabType.DOUBLE).addModels(new ConfiguredModel(doubleslab));
}
protected void fourWayBlock(FourWayBlock block, ModelFile post, ModelFile side) {
public void fourWayBlock(FourWayBlock block, ModelFile post, ModelFile side) {
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
.part().modelFile(post).addModel().end();
fourWayMultipart(builder, side);
}
protected void fourWayMultipart(MultiPartBlockStateBuilder builder, ModelFile side) {
public void fourWayMultipart(MultiPartBlockStateBuilder builder, ModelFile side) {
SixWayBlock.FACING_TO_PROPERTY_MAP.entrySet().forEach(e -> {
Direction dir = e.getKey();
if (dir.getAxis().isHorizontal()) {
@@ -330,32 +360,32 @@ public abstract class BlockStateProvider extends BlockModelProvider {
});
}
protected void fenceBlock(FenceBlock block, ResourceLocation texture) {
public void fenceBlock(FenceBlock block, ResourceLocation texture) {
String baseName = block.getRegistryName().toString();
fourWayBlock(block, fencePost(baseName + "_post", texture), fenceSide(baseName + "_side", texture));
fourWayBlock(block, models().fencePost(baseName + "_post", texture), models().fenceSide(baseName + "_side", texture));
}
protected void fenceBlock(FenceBlock block, String name, ResourceLocation texture) {
fourWayBlock(block, fencePost(name + "_fence_post", texture), fenceSide(name + "_fence_side", texture));
public void fenceBlock(FenceBlock block, String name, ResourceLocation texture) {
fourWayBlock(block, models().fencePost(name + "_fence_post", texture), models().fenceSide(name + "_fence_side", texture));
}
protected void fenceGateBlock(FenceGateBlock block, ResourceLocation texture) {
public void fenceGateBlock(FenceGateBlock block, ResourceLocation texture) {
fenceGateBlockInternal(block, block.getRegistryName().toString(), texture);
}
protected void fenceGateBlock(FenceGateBlock block, String name, ResourceLocation texture) {
public void fenceGateBlock(FenceGateBlock block, String name, ResourceLocation texture) {
fenceGateBlockInternal(block, name + "_fence_gate", texture);
}
private void fenceGateBlockInternal(FenceGateBlock block, String baseName, ResourceLocation texture) {
ModelFile gate = fenceGate(baseName, texture);
ModelFile gateOpen = fenceGateOpen(baseName + "_open", texture);
ModelFile gateWall = fenceGateWall(baseName + "_wall", texture);
ModelFile gateWallOpen = fenceGateWallOpen(baseName + "_wall_open", texture);
ModelFile gate = models().fenceGate(baseName, texture);
ModelFile gateOpen = models().fenceGateOpen(baseName + "_open", texture);
ModelFile gateWall = models().fenceGateWall(baseName + "_wall", texture);
ModelFile gateWallOpen = models().fenceGateWallOpen(baseName + "_wall_open", texture);
fenceGateBlock(block, gate, gateOpen, gateWall, gateWallOpen);
}
protected void fenceGateBlock(FenceGateBlock block, ModelFile gate, ModelFile gateOpen, ModelFile gateWall, ModelFile gateWallOpen) {
public void fenceGateBlock(FenceGateBlock block, ModelFile gate, ModelFile gateOpen, ModelFile gateWall, ModelFile gateWallOpen) {
getVariantBuilder(block).forAllStatesExcept(state -> {
ModelFile model = gate;
if (state.get(FenceGateBlock.IN_WALL)) {
@@ -372,43 +402,43 @@ public abstract class BlockStateProvider extends BlockModelProvider {
}, FenceGateBlock.POWERED);
}
protected void wallBlock(WallBlock block, ResourceLocation texture) {
public void wallBlock(WallBlock block, ResourceLocation texture) {
wallBlockInternal(block, block.getRegistryName().toString(), texture);
}
protected void wallBlock(WallBlock block, String name, ResourceLocation texture) {
public void wallBlock(WallBlock block, String name, ResourceLocation texture) {
wallBlockInternal(block, name + "_wall", texture);
}
private void wallBlockInternal(WallBlock block, String baseName, ResourceLocation texture) {
wallBlock(block, wallPost(baseName + "_post", texture), wallSide(baseName + "_side", texture));
wallBlock(block, models().wallPost(baseName + "_post", texture), models().wallSide(baseName + "_side", texture));
}
protected void wallBlock(WallBlock block, ModelFile post, ModelFile side) {
public void wallBlock(WallBlock block, ModelFile post, ModelFile side) {
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
.part().modelFile(post).addModel()
.condition(WallBlock.UP, true).end();
fourWayMultipart(builder, side);
}
protected void paneBlock(PaneBlock block, ResourceLocation pane, ResourceLocation edge) {
public void paneBlock(PaneBlock block, ResourceLocation pane, ResourceLocation edge) {
paneBlockInternal(block, block.getRegistryName().toString(), pane, edge);
}
protected void paneBlock(PaneBlock block, String name, ResourceLocation pane, ResourceLocation edge) {
public void paneBlock(PaneBlock block, String name, ResourceLocation pane, ResourceLocation edge) {
paneBlockInternal(block, name + "_pane", pane, edge);
}
private void paneBlockInternal(PaneBlock block, String baseName, ResourceLocation pane, ResourceLocation edge) {
ModelFile post = panePost(baseName + "_post", pane, edge);
ModelFile side = paneSide(baseName + "_side", pane, edge);
ModelFile sideAlt = paneSideAlt(baseName + "_side_alt", pane, edge);
ModelFile noSide = paneNoSide(baseName + "_noside", pane);
ModelFile noSideAlt = paneNoSideAlt(baseName + "_noside_alt", pane);
ModelFile post = models().panePost(baseName + "_post", pane, edge);
ModelFile side = models().paneSide(baseName + "_side", pane, edge);
ModelFile sideAlt = models().paneSideAlt(baseName + "_side_alt", pane, edge);
ModelFile noSide = models().paneNoSide(baseName + "_noside", pane);
ModelFile noSideAlt = models().paneNoSideAlt(baseName + "_noside_alt", pane);
paneBlock(block, post, side, sideAlt, noSide, noSideAlt);
}
protected void paneBlock(PaneBlock block, ModelFile post, ModelFile side, ModelFile sideAlt, ModelFile noSide, ModelFile noSideAlt) {
public void paneBlock(PaneBlock block, ModelFile post, ModelFile side, ModelFile sideAlt, ModelFile noSide, ModelFile noSideAlt) {
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
.part().modelFile(post).addModel().end();
SixWayBlock.FACING_TO_PROPERTY_MAP.entrySet().forEach(e -> {
@@ -423,23 +453,23 @@ public abstract class BlockStateProvider extends BlockModelProvider {
});
}
protected void doorBlock(DoorBlock block, ResourceLocation bottom, ResourceLocation top) {
public void doorBlock(DoorBlock block, ResourceLocation bottom, ResourceLocation top) {
doorBlockInternal(block, block.getRegistryName().toString(), bottom, top);
}
protected void doorBlock(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top) {
public void doorBlock(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top) {
doorBlockInternal(block, name + "_door", bottom, top);
}
private void doorBlockInternal(DoorBlock block, String baseName, ResourceLocation bottom, ResourceLocation top) {
ModelFile bottomLeft = doorBottomLeft(baseName + "_bottom", bottom, top);
ModelFile bottomRight = doorBottomRight(baseName + "_bottom_hinge", bottom, top);
ModelFile topLeft = doorTopLeft(baseName + "_top", bottom, top);
ModelFile topRight = doorTopRight(baseName + "_top_hinge", bottom, top);
ModelFile bottomLeft = models().doorBottomLeft(baseName + "_bottom", bottom, top);
ModelFile bottomRight = models().doorBottomRight(baseName + "_bottom_hinge", bottom, top);
ModelFile topLeft = models().doorTopLeft(baseName + "_top", bottom, top);
ModelFile topRight = models().doorTopRight(baseName + "_top_hinge", bottom, top);
doorBlock(block, bottomLeft, bottomRight, topLeft, topRight);
}
protected void doorBlock(DoorBlock block, ModelFile bottomLeft, ModelFile bottomRight, ModelFile topLeft, ModelFile topRight) {
public void doorBlock(DoorBlock block, ModelFile bottomLeft, ModelFile bottomRight, ModelFile topLeft, ModelFile topRight) {
getVariantBuilder(block).forAllStatesExcept(state -> {
int yRot = ((int) state.get(DoorBlock.FACING).getHorizontalAngle()) + 90;
boolean rh = state.get(DoorBlock.HINGE) == DoorHingeSide.RIGHT;
@@ -458,22 +488,22 @@ public abstract class BlockStateProvider extends BlockModelProvider {
}, DoorBlock.POWERED);
}
protected void trapdoorBlock(TrapDoorBlock block, ResourceLocation texture, boolean orientable) {
public void trapdoorBlock(TrapDoorBlock block, ResourceLocation texture, boolean orientable) {
trapdoorBlockInternal(block, block.getRegistryName().toString(), texture, orientable);
}
protected void trapdoorBlock(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable) {
public void trapdoorBlock(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable) {
trapdoorBlockInternal(block, name + "_trapdoor", texture, orientable);
}
private void trapdoorBlockInternal(TrapDoorBlock block, String baseName, ResourceLocation texture, boolean orientable) {
ModelFile bottom = orientable ? trapdoorOrientableBottom(baseName + "_bottom", texture) : trapdoorBottom(baseName + "_bottom", texture);
ModelFile top = orientable ? trapdoorOrientableTop(baseName + "_top", texture) : trapdoorTop(baseName + "_top", texture);
ModelFile open = orientable ? trapdoorOrientableOpen(baseName + "_open", texture) : trapdoorOpen(baseName + "_open", texture);
ModelFile bottom = orientable ? models().trapdoorOrientableBottom(baseName + "_bottom", texture) : models().trapdoorBottom(baseName + "_bottom", texture);
ModelFile top = orientable ? models().trapdoorOrientableTop(baseName + "_top", texture) : models().trapdoorTop(baseName + "_top", texture);
ModelFile open = orientable ? models().trapdoorOrientableOpen(baseName + "_open", texture) : models().trapdoorOpen(baseName + "_open", texture);
trapdoorBlock(block, bottom, top, open, orientable);
}
protected void trapdoorBlock(TrapDoorBlock block, ModelFile bottom, ModelFile top, ModelFile open, boolean orientable) {
public void trapdoorBlock(TrapDoorBlock block, ModelFile bottom, ModelFile top, ModelFile open, boolean orientable) {
getVariantBuilder(block).forAllStatesExcept(state -> {
int xRot = 0;
int yRot = ((int) state.get(TrapDoorBlock.HORIZONTAL_FACING).getHorizontalAngle()) + 180;
@@ -493,7 +523,7 @@ public abstract class BlockStateProvider extends BlockModelProvider {
}, TrapDoorBlock.POWERED, TrapDoorBlock.WATERLOGGED);
}
private void saveBlockState(JsonObject stateJson, Block owner) {
private void saveBlockState(DirectoryCache cache, JsonObject stateJson, Block owner) {
ResourceLocation blockName = Preconditions.checkNotNull(owner.getRegistryName());
Path mainOutput = generator.getOutputFolder();
String pathSuffix = "assets/" + blockName.getNamespace() + "/blockstates/" + blockName.getPath() + ".json";
@@ -67,10 +67,9 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
protected final String folder;
protected final Function<ResourceLocation, T> factory;
@VisibleForTesting
protected final Map<ResourceLocation, T> generatedModels = new HashMap<>();
protected final ExistingFileHelper existingFileHelper;
protected DirectoryCache cache;
public final Map<ResourceLocation, T> generatedModels = new HashMap<>();
@VisibleForTesting
public final ExistingFileHelper existingFileHelper;
protected abstract void registerModels();
@@ -91,7 +90,7 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
this(generator, modid, folder, loc->builderFromModId.apply(loc, existingFileHelper), existingFileHelper);
}
protected T getBuilder(String path) {
public T getBuilder(String path) {
Preconditions.checkNotNull(path, "Path must not be null");
ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? new ResourceLocation(path) : new ResourceLocation(modid, path));
return generatedModels.computeIfAbsent(outputLoc, factory);
@@ -104,23 +103,23 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
return new ResourceLocation(rl.getNamespace(), folder + "/" + rl.getPath());
}
protected ResourceLocation modLoc(String name) {
public ResourceLocation modLoc(String name) {
return new ResourceLocation(modid, name);
}
protected ResourceLocation mcLoc(String name) {
public ResourceLocation mcLoc(String name) {
return new ResourceLocation(name);
}
protected T withExistingParent(String name, String parent) {
public T withExistingParent(String name, String parent) {
return withExistingParent(name, mcLoc(parent));
}
protected T withExistingParent(String name, ResourceLocation parent) {
public T withExistingParent(String name, ResourceLocation parent) {
return getBuilder(name).parent(getExistingFile(parent));
}
protected T cube(String name, ResourceLocation down, ResourceLocation up, ResourceLocation north, ResourceLocation south, ResourceLocation east, ResourceLocation west) {
public T cube(String name, ResourceLocation down, ResourceLocation up, ResourceLocation north, ResourceLocation south, ResourceLocation east, ResourceLocation west) {
return withExistingParent(name, "cube")
.texture("down", down)
.texture("up", up)
@@ -134,7 +133,7 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
return singleTexture(name, mcLoc(parent), texture);
}
protected T singleTexture(String name, ResourceLocation parent, ResourceLocation texture) {
public T singleTexture(String name, ResourceLocation parent, ResourceLocation texture) {
return singleTexture(name, parent, "texture", texture);
}
@@ -142,16 +141,16 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
return singleTexture(name, mcLoc(parent), textureKey, texture);
}
protected T singleTexture(String name, ResourceLocation parent, String textureKey, ResourceLocation texture) {
public T singleTexture(String name, ResourceLocation parent, String textureKey, ResourceLocation texture) {
return withExistingParent(name, parent)
.texture(textureKey, texture);
}
protected T cubeAll(String name, ResourceLocation texture) {
public T cubeAll(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/cube_all", "all", texture);
}
protected T cubeTop(String name, ResourceLocation side, ResourceLocation top) {
public T cubeTop(String name, ResourceLocation side, ResourceLocation top) {
return withExistingParent(name, BLOCK_FOLDER + "/cube_top")
.texture("side", side)
.texture("top", top);
@@ -164,23 +163,23 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
.texture("top", top);
}
protected T cubeBottomTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T cubeBottomTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/cube_bottom_top", side, bottom, top);
}
protected T cubeColumn(String name, ResourceLocation side, ResourceLocation end) {
public T cubeColumn(String name, ResourceLocation side, ResourceLocation end) {
return withExistingParent(name, BLOCK_FOLDER + "/cube_column")
.texture("side", side)
.texture("end", end);
}
protected T orientableVertical(String name, ResourceLocation side, ResourceLocation front) {
public T orientableVertical(String name, ResourceLocation side, ResourceLocation front) {
return withExistingParent(name, BLOCK_FOLDER + "/orientable_vertical")
.texture("side", side)
.texture("front", front);
}
protected T orientableWithBottom(String name, ResourceLocation side, ResourceLocation front, ResourceLocation bottom, ResourceLocation top) {
public T orientableWithBottom(String name, ResourceLocation side, ResourceLocation front, ResourceLocation bottom, ResourceLocation top) {
return withExistingParent(name, BLOCK_FOLDER + "/orientable_with_bottom")
.texture("side", side)
.texture("front", front)
@@ -188,78 +187,78 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
.texture("top", top);
}
protected T orientable(String name, ResourceLocation side, ResourceLocation front, ResourceLocation top) {
public T orientable(String name, ResourceLocation side, ResourceLocation front, ResourceLocation top) {
return withExistingParent(name, BLOCK_FOLDER + "/orientable")
.texture("side", side)
.texture("front", front)
.texture("top", top);
}
protected T crop(String name, ResourceLocation crop) {
public T crop(String name, ResourceLocation crop) {
return singleTexture(name, BLOCK_FOLDER + "/crop", "crop", crop);
}
protected T cross(String name, ResourceLocation cross) {
public T cross(String name, ResourceLocation cross) {
return singleTexture(name, BLOCK_FOLDER + "/cross", "cross", cross);
}
protected T stairs(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T stairs(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/stairs", side, bottom, top);
}
protected T stairsOuter(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T stairsOuter(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/outer_stairs", side, bottom, top);
}
protected T stairsInner(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T stairsInner(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/inner_stairs", side, bottom, top);
}
protected T slab(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T slab(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/slab", side, bottom, top);
}
protected T slabTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
public T slabTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
return sideBottomTop(name, BLOCK_FOLDER + "/slab_top", side, bottom, top);
}
protected T fencePost(String name, ResourceLocation texture) {
public T fencePost(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/fence_post", texture);
}
protected T fenceSide(String name, ResourceLocation texture) {
public T fenceSide(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/fence_side", texture);
}
protected T fenceInventory(String name, ResourceLocation texture) {
public T fenceInventory(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/fence_inventory", texture);
}
protected T fenceGate(String name, ResourceLocation texture) {
public T fenceGate(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_fence_gate", texture);
}
protected T fenceGateOpen(String name, ResourceLocation texture) {
public T fenceGateOpen(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_fence_gate_open", texture);
}
protected T fenceGateWall(String name, ResourceLocation texture) {
public T fenceGateWall(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_fence_gate_wall", texture);
}
protected T fenceGateWallOpen(String name, ResourceLocation texture) {
public T fenceGateWallOpen(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_fence_gate_wall_open", texture);
}
protected T wallPost(String name, ResourceLocation wall) {
public T wallPost(String name, ResourceLocation wall) {
return singleTexture(name, BLOCK_FOLDER + "/template_wall_post", "wall", wall);
}
protected T wallSide(String name, ResourceLocation wall) {
public T wallSide(String name, ResourceLocation wall) {
return singleTexture(name, BLOCK_FOLDER + "/template_wall_side", "wall", wall);
}
protected T wallInventory(String name, ResourceLocation wall) {
public T wallInventory(String name, ResourceLocation wall) {
return singleTexture(name, BLOCK_FOLDER + "/wall_inventory", "wall", wall);
}
@@ -269,23 +268,23 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
.texture("edge", edge);
}
protected T panePost(String name, ResourceLocation pane, ResourceLocation edge) {
public T panePost(String name, ResourceLocation pane, ResourceLocation edge) {
return pane(name, "template_glass_pane_post", pane, edge);
}
protected T paneSide(String name, ResourceLocation pane, ResourceLocation edge) {
public T paneSide(String name, ResourceLocation pane, ResourceLocation edge) {
return pane(name, "template_glass_pane_side", pane, edge);
}
protected T paneSideAlt(String name, ResourceLocation pane, ResourceLocation edge) {
public T paneSideAlt(String name, ResourceLocation pane, ResourceLocation edge) {
return pane(name, "template_glass_pane_side_alt", pane, edge);
}
protected T paneNoSide(String name, ResourceLocation pane) {
public T paneNoSide(String name, ResourceLocation pane) {
return singleTexture(name, BLOCK_FOLDER + "/template_glass_pane_noside", "pane", pane);
}
protected T paneNoSideAlt(String name, ResourceLocation pane) {
public T paneNoSideAlt(String name, ResourceLocation pane) {
return singleTexture(name, BLOCK_FOLDER + "/template_glass_pane_noside_alt", "pane", pane);
}
@@ -295,74 +294,76 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
.texture("top", top);
}
protected T doorBottomLeft(String name, ResourceLocation bottom, ResourceLocation top) {
public T doorBottomLeft(String name, ResourceLocation bottom, ResourceLocation top) {
return door(name, "door_bottom", bottom, top);
}
protected T doorBottomRight(String name, ResourceLocation bottom, ResourceLocation top) {
public T doorBottomRight(String name, ResourceLocation bottom, ResourceLocation top) {
return door(name, "door_bottom_rh", bottom, top);
}
protected T doorTopLeft(String name, ResourceLocation bottom, ResourceLocation top) {
public T doorTopLeft(String name, ResourceLocation bottom, ResourceLocation top) {
return door(name, "door_top", bottom, top);
}
protected T doorTopRight(String name, ResourceLocation bottom, ResourceLocation top) {
public T doorTopRight(String name, ResourceLocation bottom, ResourceLocation top) {
return door(name, "door_top_rh", bottom, top);
}
protected T trapdoorBottom(String name, ResourceLocation texture) {
public T trapdoorBottom(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_trapdoor_bottom", texture);
}
protected T trapdoorTop(String name, ResourceLocation texture) {
public T trapdoorTop(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_trapdoor_top", texture);
}
protected T trapdoorOpen(String name, ResourceLocation texture) {
public T trapdoorOpen(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_trapdoor_open", texture);
}
protected T trapdoorOrientableBottom(String name, ResourceLocation texture) {
public T trapdoorOrientableBottom(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_orientable_trapdoor_bottom", texture);
}
protected T trapdoorOrientableTop(String name, ResourceLocation texture) {
public T trapdoorOrientableTop(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_orientable_trapdoor_top", texture);
}
protected T trapdoorOrientableOpen(String name, ResourceLocation texture) {
public T trapdoorOrientableOpen(String name, ResourceLocation texture) {
return singleTexture(name, BLOCK_FOLDER + "/template_orientable_trapdoor_open", texture);
}
protected T torch(String name, ResourceLocation torch) {
public T torch(String name, ResourceLocation torch) {
return singleTexture(name, BLOCK_FOLDER + "/template_torch", "torch", torch);
}
protected T torchWall(String name, ResourceLocation torch) {
public T torchWall(String name, ResourceLocation torch) {
return singleTexture(name, BLOCK_FOLDER + "/torch_wall", "torch", torch);
}
protected T carpet(String name, ResourceLocation wool) {
public T carpet(String name, ResourceLocation wool) {
return singleTexture(name, BLOCK_FOLDER + "/carpet", "wool", wool);
}
protected ModelFile.ExistingModelFile getExistingFile(ResourceLocation path) {
public ModelFile.ExistingModelFile getExistingFile(ResourceLocation path) {
ModelFile.ExistingModelFile ret = new ModelFile.ExistingModelFile(extendWithFolder(path), existingFileHelper);
ret.assertExistence();
return ret;
}
protected void clear() {
generatedModels.clear();
}
@Override
public void act(DirectoryCache cache) throws IOException {
this.cache = cache;
generatedModels.clear();
clear();
registerModels();
generateAll();
this.cache = null;
generateAll(cache);
}
private void generateAll() {
protected void generateAll(DirectoryCache cache) {
for (T model : generatedModels.values()) {
Path target = getPath(model);
try {
@@ -87,63 +87,63 @@ public abstract class LanguageProvider implements IDataProvider {
cache.func_208316_a(target, hash);
}
protected void addBlock(Supplier<? extends Block> key, String name) {
public void addBlock(Supplier<? extends Block> key, String name) {
add(key.get(), name);
}
protected void add(Block key, String name) {
public void add(Block key, String name) {
add(key.getTranslationKey(), name);
}
protected void addItem(Supplier<? extends Item> key, String name) {
public void addItem(Supplier<? extends Item> key, String name) {
add(key.get(), name);
}
protected void add(Item key, String name) {
public void add(Item key, String name) {
add(key.getTranslationKey(), name);
}
protected void addItemStack(Supplier<ItemStack> key, String name) {
public void addItemStack(Supplier<ItemStack> key, String name) {
add(key.get(), name);
}
protected void add(ItemStack key, String name) {
public void add(ItemStack key, String name) {
add(key.getTranslationKey(), name);
}
protected void addEnchantment(Supplier<? extends Enchantment> key, String name) {
public void addEnchantment(Supplier<? extends Enchantment> key, String name) {
add(key.get(), name);
}
protected void add(Enchantment key, String name) {
public void add(Enchantment key, String name) {
add(key.getName(), name);
}
protected void addBiome(Supplier<? extends Biome> key, String name) {
public void addBiome(Supplier<? extends Biome> key, String name) {
add(key.get(), name);
}
protected void add(Biome key, String name) {
public void add(Biome key, String name) {
add(key.getTranslationKey(), name);
}
protected void addEffect(Supplier<? extends Effect> key, String name) {
public void addEffect(Supplier<? extends Effect> key, String name) {
add(key.get(), name);
}
protected void add(Effect key, String name) {
public void add(Effect key, String name) {
add(key.getName(), name);
}
protected void addEntityType(Supplier<? extends EntityType<?>> key, String name) {
public void addEntityType(Supplier<? extends EntityType<?>> key, String name) {
add(key.get(), name);
}
protected void add(EntityType<?> key, String name) {
public void add(EntityType<?> key, String name) {
add(key.getTranslationKey(), name);
}
protected void add(String key, String value) {
public void add(String key, String value) {
if (data.put(key, value) != null)
throw new IllegalStateException("Duplicate translation key " + key);
}