mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add fast graphics render type to block model jsons (#10395)
Make modded leaves behave like vanilla leaves by default (Fixes #10389)
This commit is contained in:
1 parent
979abb2b93
commit
ab00c907e7
19 files changed
+708
-54
No files matched your search
@@ -208,6 +208,7 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel> {
|
||||
private final ItemTransforms transforms;
|
||||
private TextureAtlasSprite particle;
|
||||
private RenderTypeGroup lastRenderTypes = RenderTypeGroup.EMPTY;
|
||||
private RenderTypeGroup lastRenderTypesFast = RenderTypeGroup.EMPTY;
|
||||
|
||||
private Builder(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemTransforms transforms) {
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
@@ -218,23 +219,32 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel> {
|
||||
}
|
||||
|
||||
public void addLayer(BakedModel model) {
|
||||
flushQuads(null);
|
||||
flushQuads(RenderTypeGroup.EMPTY, RenderTypeGroup.EMPTY);
|
||||
children.add(model);
|
||||
}
|
||||
|
||||
private void addLayer(RenderTypeGroup renderTypes, List<BakedQuad> quads) {
|
||||
var modelBuilder = IModelBuilder.of(isAmbientOcclusion, isSideLit, isGui3d, transforms, particle, renderTypes);
|
||||
this.addLayer(renderTypes, RenderTypeGroup.EMPTY, quads);
|
||||
}
|
||||
|
||||
private void addLayer(RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast, List<BakedQuad> quads) {
|
||||
var modelBuilder = IModelBuilder.of(isAmbientOcclusion, isSideLit, isGui3d, transforms, particle, renderTypes, renderTypesFast);
|
||||
quads.forEach(modelBuilder::addUnculledFace);
|
||||
children.add(modelBuilder.build());
|
||||
}
|
||||
|
||||
private void flushQuads(RenderTypeGroup renderTypes) {
|
||||
this.flushQuads(renderTypes, RenderTypeGroup.EMPTY);
|
||||
}
|
||||
|
||||
private void flushQuads(RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast) {
|
||||
if (!Objects.equals(renderTypes, lastRenderTypes)) {
|
||||
if (!quads.isEmpty()) {
|
||||
addLayer(lastRenderTypes, quads);
|
||||
addLayer(lastRenderTypes, lastRenderTypesFast, quads);
|
||||
quads.clear();
|
||||
}
|
||||
lastRenderTypes = renderTypes;
|
||||
lastRenderTypesFast = renderTypesFast;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,20 +254,28 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel> {
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, BakedQuad... quadsToAdd) {
|
||||
flushQuads(renderTypes);
|
||||
return this.addQuads(renderTypes, RenderTypeGroup.EMPTY, quadsToAdd);
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast, BakedQuad... quadsToAdd) {
|
||||
flushQuads(renderTypes, renderTypesFast);
|
||||
Collections.addAll(quads, quadsToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, Collection<BakedQuad> quadsToAdd) {
|
||||
flushQuads(renderTypes);
|
||||
return this.addQuads(renderTypes, RenderTypeGroup.EMPTY, quadsToAdd);
|
||||
}
|
||||
|
||||
public Builder addQuads(RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast, Collection<BakedQuad> quadsToAdd) {
|
||||
flushQuads(renderTypes, renderTypesFast);
|
||||
quads.addAll(quadsToAdd);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BakedModel build() {
|
||||
if (!quads.isEmpty()) {
|
||||
addLayer(lastRenderTypes, quads);
|
||||
addLayer(lastRenderTypes, lastRenderTypesFast, quads);
|
||||
}
|
||||
var childrenBuilder = ImmutableMap.<String, BakedModel>builder();
|
||||
var itemPassesBuilder = ImmutableList.<BakedModel>builder();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class EmptyModel extends SimpleUnbakedGeometry<EmptyModel> {
|
||||
private static final Material MISSING_TEXTURE = new Material(InventoryMenu.BLOCK_ATLAS, MissingTextureAtlasSprite.getLocation());
|
||||
|
||||
public Baked() {
|
||||
super(List.of(), Map.of(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, RenderTypeGroup.EMPTY);
|
||||
super(List.of(), Map.of(), false, false, false, UnitTextureAtlasSprite.INSTANCE, ItemTransforms.NO_TRANSFORMS, RenderTypeGroup.EMPTY, RenderTypeGroup.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,12 @@ public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
model.customData.setRenderTypeHint(ResourceLocation.parse(renderTypeHintName));
|
||||
}
|
||||
|
||||
if (jsonobject.has("render_type_fast"))
|
||||
{
|
||||
var renderTypeHintName = GsonHelper.getAsString(jsonobject, "render_type_fast");
|
||||
model.customData.setRenderTypeFastHint(ResourceLocation.parse(renderTypeHintName));
|
||||
}
|
||||
|
||||
if (jsonobject.has("visibility"))
|
||||
{
|
||||
JsonObject visibility = GsonHelper.getAsJsonObject(jsonobject, "visibility");
|
||||
|
||||
@@ -32,6 +32,18 @@ public interface IModelBuilder<T extends IModelBuilder<T>> {
|
||||
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes);
|
||||
}
|
||||
|
||||
static IModelBuilder<?> of(
|
||||
boolean hasAmbientOcclusion,
|
||||
boolean usesBlockLight,
|
||||
boolean isGui3d,
|
||||
ItemTransforms transforms,
|
||||
TextureAtlasSprite particle,
|
||||
RenderTypeGroup renderTypes,
|
||||
RenderTypeGroup renderTypesFast
|
||||
){
|
||||
return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, renderTypesFast);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new model builder that collects quads to the provided list, returning
|
||||
* {@linkplain EmptyModel#BAKED an empty model} if you call {@link #build()}.
|
||||
@@ -49,12 +61,20 @@ public interface IModelBuilder<T extends IModelBuilder<T>> {
|
||||
class Simple implements IModelBuilder<Simple> {
|
||||
private final SimpleBakedModel.Builder builder;
|
||||
private final RenderTypeGroup renderTypes;
|
||||
private final RenderTypeGroup renderTypesFast;
|
||||
|
||||
private Simple(boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
|
||||
ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes
|
||||
) {
|
||||
this(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, RenderTypeGroup.EMPTY);
|
||||
}
|
||||
|
||||
private Simple(boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,
|
||||
ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast
|
||||
) {
|
||||
this.builder = new SimpleBakedModel.Builder(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms).particle(particle);
|
||||
this.renderTypes = renderTypes;
|
||||
this.renderTypesFast = renderTypesFast;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,10 +39,16 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel> {
|
||||
@Nullable
|
||||
private ImmutableList<Material> textures;
|
||||
private final Int2ObjectMap<ResourceLocation> renderTypeNames;
|
||||
private final Int2ObjectMap<ResourceLocation> renderTypeFastNames;
|
||||
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames) {
|
||||
this(textures, renderTypeNames, new Int2ObjectOpenHashMap<>());
|
||||
}
|
||||
|
||||
private ItemLayerModel(@Nullable ImmutableList<Material> textures, Int2ObjectMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ResourceLocation> renderTypeFastNames) {
|
||||
this.textures = textures;
|
||||
this.renderTypeNames = renderTypeNames;
|
||||
this.renderTypeFastNames = renderTypeFastNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +75,9 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel> {
|
||||
var quads = UnbakedGeometryHelper.bakeElements(unbaked, $ -> sprite, modelState);
|
||||
var renderTypeName = renderTypeNames.get(i);
|
||||
var renderTypes = renderTypeName != null ? context.getRenderType(renderTypeName) : null;
|
||||
builder.addQuads(renderTypes != null ? renderTypes : normalRenderTypes, quads);
|
||||
var renderTypeFastName = renderTypeFastNames.get(i);
|
||||
var renderTypesFast = renderTypeFastName != null ? context.getRenderType(renderTypeFastName) : null;
|
||||
builder.addQuads(renderTypes != null ? renderTypes : normalRenderTypes, renderTypesFast != null ? renderTypesFast : RenderTypeGroup.EMPTY, quads);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
@@ -80,20 +88,27 @@ public class ItemLayerModel implements IUnbakedGeometry<ItemLayerModel> {
|
||||
|
||||
@Override
|
||||
public ItemLayerModel read(JsonObject jsonObject, JsonDeserializationContext deserializationContext) {
|
||||
var renderTypeNames = readRenderTypeNames(jsonObject, "render_types");
|
||||
var renderTypeFastNames = readRenderTypeNames(jsonObject, "render_types_fast");
|
||||
return new ItemLayerModel(null, renderTypeNames, renderTypeFastNames);
|
||||
}
|
||||
|
||||
private static Int2ObjectMap<ResourceLocation> readRenderTypeNames(JsonObject jsonObject, String key) {
|
||||
var renderTypeNames = new Int2ObjectOpenHashMap<ResourceLocation>();
|
||||
if (jsonObject.has("render_types")) {
|
||||
var renderTypes = jsonObject.getAsJsonObject("render_types");
|
||||
if (jsonObject.has(key)) {
|
||||
var renderTypes = jsonObject.getAsJsonObject(key);
|
||||
for (var entry : renderTypes.entrySet()) {
|
||||
var renderType = ResourceLocation.parse(entry.getKey());
|
||||
for (var layer : entry.getValue().getAsJsonArray())
|
||||
if (renderTypeNames.put(layer.getAsInt(), renderType) != null)
|
||||
throw new JsonParseException("Registered duplicate render type for layer " + layer);
|
||||
throw new JsonParseException("Registered duplicate " + key + " for layer " + layer);
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemLayerModel(null, renderTypeNames);
|
||||
return renderTypeNames;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.21.4")
|
||||
protected void readLayerData(JsonObject jsonObject, String name, Int2ObjectOpenHashMap<ResourceLocation> renderTypeNames, Int2ObjectMap<ForgeFaceData> layerData, boolean logWarning) {
|
||||
if (!jsonObject.has(name))
|
||||
return;
|
||||
|
||||
@@ -250,6 +250,42 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
models().cubeColumnHorizontal(name(block) + "_horizontal", side, end).renderType(renderType));
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, String renderType, String renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, blockTexture(block), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void logBlockWithRenderTypeAndFast(RotatedPillarBlock block, String renderType, String renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, blockTexture(block), extend(blockTexture(block), "_top"), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, ResourceLocation baseName, String renderType, String renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, extend(baseName, "_side"), extend(baseName, "_end"), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, ResourceLocation side, ResourceLocation end, String renderType, String renderTypeFast) {
|
||||
axisBlock(block,
|
||||
models().cubeColumn(name(block), side, end).renderType(renderType, renderTypeFast),
|
||||
models().cubeColumnHorizontal(name(block) + "_horizontal", side, end).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, blockTexture(block), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void logBlockWithRenderType(RotatedPillarBlock block, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, blockTexture(block), extend(blockTexture(block), "_top"), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, ResourceLocation baseName, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
axisBlockWithRenderTypeAndFast(block, extend(baseName, "_side"), extend(baseName, "_end"), renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void axisBlockWithRenderTypeAndFast(RotatedPillarBlock block, ResourceLocation side, ResourceLocation end, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
axisBlock(block,
|
||||
models().cubeColumn(name(block), side, end).renderType(renderType, renderTypeFast),
|
||||
models().cubeColumnHorizontal(name(block) + "_horizontal", side, end).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void axisBlock(RotatedPillarBlock block, ModelFile vertical, ModelFile horizontal) {
|
||||
getVariantBuilder(block)
|
||||
.partialState().with(RotatedPillarBlock.AXIS, Axis.Y)
|
||||
@@ -381,6 +417,38 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
stairsBlockInternalWithRenderType(block, name + "_stairs", side, bottom, top, renderType);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
stairsBlockWithRenderTypeAndFast(block, texture, texture, texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, String name, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
stairsBlockWithRenderTypeAndFast(block, name, texture, texture, texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top, String renderType, String renderTypeFast) {
|
||||
stairsBlockInternalWithRenderTypeAndFast(block, key(block).toString(), side, bottom, top, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top, String renderType, String renderTypeFast) {
|
||||
stairsBlockInternalWithRenderTypeAndFast(block, name + "_stairs", side, bottom, top, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
stairsBlockWithRenderTypeAndFast(block, texture, texture, texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, String name, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
stairsBlockWithRenderTypeAndFast(block, name, texture, texture, texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
stairsBlockInternalWithRenderTypeAndFast(block, key(block).toString(), side, bottom, top, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void stairsBlockWithRenderTypeAndFast(StairBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
stairsBlockInternalWithRenderTypeAndFast(block, name + "_stairs", side, bottom, top, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void stairsBlockInternal(StairBlock block, String baseName, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
|
||||
ModelFile stairs = models().stairs(baseName, side, bottom, top);
|
||||
ModelFile stairsInner = models().stairsInner(baseName + "_inner", side, bottom, top);
|
||||
@@ -395,6 +463,13 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
stairsBlock(block, stairs, stairsInner, stairsOuter);
|
||||
}
|
||||
|
||||
private void stairsBlockInternalWithRenderTypeAndFast(StairBlock block, String baseName, ResourceLocation side, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
ModelFile stairs = models().stairs(baseName, side, bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile stairsInner = models().stairsInner(baseName + "_inner", side, bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile stairsOuter = models().stairsOuter(baseName + "_outer", side, bottom, top).renderType(renderType, renderTypeFast);
|
||||
stairsBlock(block, stairs, stairsInner, stairsOuter);
|
||||
}
|
||||
|
||||
public void stairsBlock(StairBlock block, ModelFile stairs, ModelFile stairsInner, ModelFile stairsOuter) {
|
||||
getVariantBuilder(block)
|
||||
.forAllStatesExcept(state -> {
|
||||
@@ -532,6 +607,32 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
models().fenceSide(name + "_fence_side", texture).renderType(renderType));
|
||||
}
|
||||
|
||||
public void fenceBlockWithRenderTypeAndFast(FenceBlock block, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
String baseName = key(block).toString();
|
||||
fourWayBlock(block,
|
||||
models().fencePost(baseName + "_post", texture).renderType(renderType, renderTypeFast),
|
||||
models().fenceSide(baseName + "_side", texture).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceBlockWithRenderTypeAndFast(FenceBlock block, String name, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
fourWayBlock(block,
|
||||
models().fencePost(name + "_fence_post", texture).renderType(renderType, renderTypeFast),
|
||||
models().fenceSide(name + "_fence_side", texture).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceBlockWithRenderTypeAndFast(FenceBlock block, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
String baseName = key(block).toString();
|
||||
fourWayBlock(block,
|
||||
models().fencePost(baseName + "_post", texture).renderType(renderType, renderTypeFast),
|
||||
models().fenceSide(baseName + "_side", texture).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceBlockWithRenderTypeAndFast(FenceBlock block, String name, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
fourWayBlock(block,
|
||||
models().fencePost(name + "_fence_post", texture).renderType(renderType, renderTypeFast),
|
||||
models().fenceSide(name + "_fence_side", texture).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceGateBlock(FenceGateBlock block, ResourceLocation texture) {
|
||||
fenceGateBlockInternal(block, key(block).toString(), texture);
|
||||
}
|
||||
@@ -556,6 +657,22 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
fenceGateBlockInternalWithRenderType(block, name + "_fence_gate", texture, renderType);
|
||||
}
|
||||
|
||||
public void fenceGateBlockWithRenderTypeAndFast(FenceGateBlock block, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
fenceGateBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceGateBlockWithRenderTypeAndFast(FenceGateBlock block, String name, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
fenceGateBlockInternalWithRenderTypeAndFast(block, name + "_fence_gate", texture, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void fenceGateBlockWithRenderTypeAndFast(FenceGateBlock block, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
fenceGateBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void fenceGateBlockWithRenderTypeAndFast(FenceGateBlock block, String name, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
fenceGateBlockInternalWithRenderTypeAndFast(block, name + "_fence_gate", texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void fenceGateBlockInternal(FenceGateBlock block, String baseName, ResourceLocation texture) {
|
||||
ModelFile gate = models().fenceGate(baseName, texture);
|
||||
ModelFile gateOpen = models().fenceGateOpen(baseName + "_open", texture);
|
||||
@@ -572,6 +689,14 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
fenceGateBlock(block, gate, gateOpen, gateWall, gateWallOpen);
|
||||
}
|
||||
|
||||
private void fenceGateBlockInternalWithRenderTypeAndFast(FenceGateBlock block, String baseName, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
ModelFile gate = models().fenceGate(baseName, texture).renderType(renderType, renderTypeFast);
|
||||
ModelFile gateOpen = models().fenceGateOpen(baseName + "_open", texture).renderType(renderType, renderTypeFast);
|
||||
ModelFile gateWall = models().fenceGateWall(baseName + "_wall", texture).renderType(renderType, renderTypeFast);
|
||||
ModelFile gateWallOpen = models().fenceGateWallOpen(baseName + "_wall_open", texture).renderType(renderType, renderTypeFast);
|
||||
fenceGateBlock(block, gate, gateOpen, gateWall, gateWallOpen);
|
||||
}
|
||||
|
||||
public void fenceGateBlock(FenceGateBlock block, ModelFile gate, ModelFile gateOpen, ModelFile gateWall, ModelFile gateWallOpen) {
|
||||
getVariantBuilder(block).forAllStatesExcept(state -> {
|
||||
ModelFile model = gate;
|
||||
@@ -613,6 +738,22 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
wallBlockInternalWithRenderType(block, name + "_wall", texture, renderType);
|
||||
}
|
||||
|
||||
public void wallBlockWithRenderTypeAndFast(WallBlock block, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
wallBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void wallBlockWithRenderTypeAndFast(WallBlock block, String name, ResourceLocation texture, String renderType, String renderTypeFast) {
|
||||
wallBlockInternalWithRenderTypeAndFast(block, name + "_wall", texture, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void wallBlockWithRenderTypeAndFast(WallBlock block, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
wallBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void wallBlockWithRenderTypeAndFast(WallBlock block, String name, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
wallBlockInternalWithRenderTypeAndFast(block, name + "_wall", texture, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void wallBlockInternal(WallBlock block, String baseName, ResourceLocation texture) {
|
||||
wallBlock(block, models().wallPost(baseName + "_post", texture),
|
||||
models().wallSide(baseName + "_side", texture),
|
||||
@@ -625,6 +766,12 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
models().wallSideTall(baseName + "_side_tall", texture).renderType(renderType));
|
||||
}
|
||||
|
||||
private void wallBlockInternalWithRenderTypeAndFast(WallBlock block, String baseName, ResourceLocation texture, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
wallBlock(block, models().wallPost(baseName + "_post", texture).renderType(renderType, renderTypeFast),
|
||||
models().wallSide(baseName + "_side", texture).renderType(renderType, renderTypeFast),
|
||||
models().wallSideTall(baseName + "_side_tall", texture).renderType(renderType, renderTypeFast));
|
||||
}
|
||||
|
||||
public static final ImmutableMap<Direction, Property<WallSide>> WALL_PROPS = ImmutableMap.<Direction, Property<WallSide>>builder()
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
@@ -677,6 +824,22 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
paneBlockInternalWithRenderType(block, name + "_pane", pane, edge, renderType);
|
||||
}
|
||||
|
||||
public void paneBlockWithRenderTypeAndFast(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge, String renderType, String renderTypeFast) {
|
||||
paneBlockInternalWithRenderTypeAndFast(block, key(block).toString(), pane, edge, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void paneBlockWithRenderTypeAndFast(IronBarsBlock block, String name, ResourceLocation pane, ResourceLocation edge, String renderType, String renderTypeFast) {
|
||||
paneBlockInternalWithRenderTypeAndFast(block, name + "_pane", pane, edge, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void paneBlockWithRenderTypeAndFast(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
paneBlockInternalWithRenderTypeAndFast(block, key(block).toString(), pane, edge, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void paneBlockWithRenderTypeAndFast(IronBarsBlock block, String name, ResourceLocation pane, ResourceLocation edge, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
paneBlockInternalWithRenderTypeAndFast(block, name + "_pane", pane, edge, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void paneBlockInternal(IronBarsBlock block, String baseName, ResourceLocation pane, ResourceLocation edge) {
|
||||
ModelFile post = models().panePost(baseName + "_post", pane, edge);
|
||||
ModelFile side = models().paneSide(baseName + "_side", pane, edge);
|
||||
@@ -695,6 +858,15 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
paneBlock(block, post, side, sideAlt, noSide, noSideAlt);
|
||||
}
|
||||
|
||||
private void paneBlockInternalWithRenderTypeAndFast(IronBarsBlock block, String baseName, ResourceLocation pane, ResourceLocation edge, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
ModelFile post = models().panePost(baseName + "_post", pane, edge).renderType(renderType, renderTypeFast);
|
||||
ModelFile side = models().paneSide(baseName + "_side", pane, edge).renderType(renderType, renderTypeFast);
|
||||
ModelFile sideAlt = models().paneSideAlt(baseName + "_side_alt", pane, edge).renderType(renderType, renderTypeFast);
|
||||
ModelFile noSide = models().paneNoSide(baseName + "_noside", pane).renderType(renderType, renderTypeFast);
|
||||
ModelFile noSideAlt = models().paneNoSideAlt(baseName + "_noside_alt", pane).renderType(renderType, renderTypeFast);
|
||||
paneBlock(block, post, side, sideAlt, noSide, noSideAlt);
|
||||
}
|
||||
|
||||
public void paneBlock(IronBarsBlock block, ModelFile post, ModelFile side, ModelFile sideAlt, ModelFile noSide, ModelFile noSideAlt) {
|
||||
MultiPartBlockStateBuilder builder = getMultipartBuilder(block)
|
||||
.part().modelFile(post).addModel().end();
|
||||
@@ -734,6 +906,22 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
doorBlockInternalWithRenderType(block, name + "_door", bottom, top, renderType);
|
||||
}
|
||||
|
||||
public void doorBlockWithRenderTypeAndFast(DoorBlock block, ResourceLocation bottom, ResourceLocation top, String renderType, String renderTypeFast) {
|
||||
doorBlockInternalWithRenderTypeAndFast(block, key(block).toString(), bottom, top, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void doorBlockWithRenderTypeAndFast(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top, String renderType, String renderTypeFast) {
|
||||
doorBlockInternalWithRenderTypeAndFast(block, name + "_door", bottom, top, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void doorBlockWithRenderTypeAndFast(DoorBlock block, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
doorBlockInternalWithRenderTypeAndFast(block, key(block).toString(), bottom, top, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void doorBlockWithRenderTypeAndFast(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
doorBlockInternalWithRenderTypeAndFast(block, name + "_door", bottom, top, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void doorBlockInternal(DoorBlock block, String baseName, ResourceLocation bottom, ResourceLocation top) {
|
||||
ModelFile bottomLeft = models().doorBottomLeft(baseName + "_bottom_left", bottom, top);
|
||||
ModelFile bottomLeftOpen = models().doorBottomLeftOpen(baseName + "_bottom_left_open", bottom, top);
|
||||
@@ -758,6 +946,18 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
doorBlock(block, bottomLeft, bottomLeftOpen, bottomRight, bottomRightOpen, topLeft, topLeftOpen, topRight, topRightOpen);
|
||||
}
|
||||
|
||||
private void doorBlockInternalWithRenderTypeAndFast(DoorBlock block, String baseName, ResourceLocation bottom, ResourceLocation top, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
ModelFile bottomLeft = models().doorBottomLeft(baseName + "_bottom_left", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile bottomLeftOpen = models().doorBottomLeftOpen(baseName + "_bottom_left_open", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile bottomRight = models().doorBottomRight(baseName + "_bottom_right", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile bottomRightOpen = models().doorBottomRightOpen(baseName + "_bottom_right_open", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile topLeft = models().doorTopLeft(baseName + "_top_left", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile topLeftOpen = models().doorTopLeftOpen(baseName + "_top_left_open", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile topRight = models().doorTopRight(baseName + "_top_right", bottom, top).renderType(renderType, renderTypeFast);
|
||||
ModelFile topRightOpen = models().doorTopRightOpen(baseName + "_top_right_open", bottom, top).renderType(renderType, renderTypeFast);
|
||||
doorBlock(block, bottomLeft, bottomLeftOpen, bottomRight, bottomRightOpen, topLeft, topLeftOpen, topRight, topRightOpen);
|
||||
}
|
||||
|
||||
public void doorBlock(DoorBlock block, ModelFile bottomLeft, ModelFile bottomLeftOpen, ModelFile bottomRight, ModelFile bottomRightOpen, ModelFile topLeft, ModelFile topLeftOpen, ModelFile topRight, ModelFile topRightOpen) {
|
||||
getVariantBuilder(block).forAllStatesExcept(state -> {
|
||||
int yRot = ((int) state.getValue(DoorBlock.FACING).toYRot()) + 90;
|
||||
@@ -824,6 +1024,22 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
trapdoorBlockInternalWithRenderType(block, name + "_trapdoor", texture, orientable, renderType);
|
||||
}
|
||||
|
||||
public void trapdoorBlockWithRenderTypeAndFast(TrapDoorBlock block, ResourceLocation texture, boolean orientable, String renderType, String renderTypeFast) {
|
||||
trapdoorBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, orientable, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void trapdoorBlockWithRenderTypeAndFast(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable, String renderType, String renderTypeFast) {
|
||||
trapdoorBlockInternalWithRenderTypeAndFast(block, name + "_trapdoor", texture, orientable, ResourceLocation.tryParse(renderType), ResourceLocation.tryParse(renderTypeFast));
|
||||
}
|
||||
|
||||
public void trapdoorBlockWithRenderTypeAndFast(TrapDoorBlock block, ResourceLocation texture, boolean orientable, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
trapdoorBlockInternalWithRenderTypeAndFast(block, key(block).toString(), texture, orientable, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
public void trapdoorBlockWithRenderTypeAndFast(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
trapdoorBlockInternalWithRenderTypeAndFast(block, name + "_trapdoor", texture, orientable, renderType, renderTypeFast);
|
||||
}
|
||||
|
||||
private void trapdoorBlockInternal(TrapDoorBlock block, String baseName, ResourceLocation texture, boolean orientable) {
|
||||
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);
|
||||
@@ -838,6 +1054,13 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
trapdoorBlock(block, bottom, top, open, orientable);
|
||||
}
|
||||
|
||||
private void trapdoorBlockInternalWithRenderTypeAndFast(TrapDoorBlock block, String baseName, ResourceLocation texture, boolean orientable, ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
ModelFile bottom = orientable ? models().trapdoorOrientableBottom(baseName + "_bottom", texture).renderType(renderType, renderTypeFast) : models().trapdoorBottom(baseName + "_bottom", texture).renderType(renderType, renderTypeFast);
|
||||
ModelFile top = orientable ? models().trapdoorOrientableTop(baseName + "_top", texture).renderType(renderType, renderTypeFast) : models().trapdoorTop(baseName + "_top", texture).renderType(renderType, renderTypeFast);
|
||||
ModelFile open = orientable ? models().trapdoorOrientableOpen(baseName + "_open", texture).renderType(renderType, renderTypeFast) : models().trapdoorOpen(baseName + "_open", texture).renderType(renderType, renderTypeFast);
|
||||
trapdoorBlock(block, bottom, top, open, orientable);
|
||||
}
|
||||
|
||||
public void trapdoorBlock(TrapDoorBlock block, ModelFile bottom, ModelFile top, ModelFile open, boolean orientable) {
|
||||
getVariantBuilder(block).forAllStatesExcept(state -> {
|
||||
int xRot = 0;
|
||||
|
||||
@@ -60,6 +60,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
protected final ExistingFileHelper existingFileHelper;
|
||||
|
||||
protected String renderType = null;
|
||||
protected String renderTypeFast = null;
|
||||
protected boolean ambientOcclusion = true;
|
||||
protected GuiLight guiLight = null;
|
||||
|
||||
@@ -149,12 +150,17 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the render type for this model.
|
||||
* Set the render type for this model. Any render types to be used must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent RegisterNamedRenderTypesEvent}.
|
||||
* <p>
|
||||
* Consider using {@linkplain #renderType(String, String)} if you need to set a render type for
|
||||
* {@linkplain net.minecraft.client.GraphicsStatus#FAST fast graphics}.
|
||||
*
|
||||
* @param renderType the render type. Must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent}
|
||||
* @param renderType the render type
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
*
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
* @see #renderType(String, String)
|
||||
*/
|
||||
public T renderType(String renderType) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
@@ -162,16 +168,55 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the render type for this model.
|
||||
* Set the render types for this model. Any render types to be used must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent RegisterNamedRenderTypesEvent}.
|
||||
*
|
||||
* @param renderType the render type. Must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent}
|
||||
* @param renderType the render type for {@linkplain net.minecraft.client.GraphicsStatus#FANCY fancy graphics}
|
||||
* @param renderTypeFast the render type for {@linkplain net.minecraft.client.GraphicsStatus#FAST fast graphics}
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
*
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
*/
|
||||
public T renderType(String renderType, String renderTypeFast) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
return renderType(ResourceLocation.parse(renderType), ResourceLocation.parse(renderTypeFast));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the render type for this model. Any render types to be used must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent RegisterNamedRenderTypesEvent}.
|
||||
* <p>
|
||||
* Consider using {@linkplain #renderType(ResourceLocation, ResourceLocation)} if you need to set a render type for
|
||||
* {@linkplain net.minecraft.client.GraphicsStatus#FAST fast graphics}.
|
||||
*
|
||||
* @param renderType the render type
|
||||
* @return this builder
|
||||
*
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
* @see #renderType(ResourceLocation, ResourceLocation)
|
||||
*/
|
||||
public T renderType(ResourceLocation renderType) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
this.renderType = renderType.toString();
|
||||
this.renderTypeFast = null;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the render types for this model. Any render types to be used must be registered via
|
||||
* {@link net.minecraftforge.client.event.RegisterNamedRenderTypesEvent RegisterNamedRenderTypesEvent}.
|
||||
*
|
||||
* @param renderType the render type for {@linkplain net.minecraft.client.GraphicsStatus#FANCY fancy graphics}
|
||||
* @param renderTypeFast the render type for {@linkplain net.minecraft.client.GraphicsStatus#FAST fast graphics}
|
||||
* @return this builder
|
||||
*
|
||||
* @throws NullPointerException if {@code renderType} is {@code null}
|
||||
*/
|
||||
public T renderType(ResourceLocation renderType, ResourceLocation renderTypeFast) {
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
Preconditions.checkNotNull(renderTypeFast, "Fast graphics render type must not be null");
|
||||
this.renderType = renderType.toString();
|
||||
this.renderTypeFast = renderType.toString();
|
||||
return self();
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +366,8 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
}
|
||||
|
||||
public T leaves(String name, ResourceLocation texture) {
|
||||
return singleTexture(name, BLOCK_FOLDER + "/leaves", "all", texture);
|
||||
return singleTexture(name, BLOCK_FOLDER + "/leaves", "all", texture)
|
||||
.renderType("cutout_mipped", "solid");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+45
@@ -34,6 +34,7 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
|
||||
private final Int2ObjectMap<ForgeFaceData> faceData = new Int2ObjectOpenHashMap<>();
|
||||
private final Map<ResourceLocation, IntSet> renderTypes = new LinkedHashMap<>();
|
||||
private final Map<ResourceLocation, IntSet> renderTypesFast = new LinkedHashMap<>();
|
||||
private final IntSet layersWithRenderTypes = new IntOpenHashSet();
|
||||
|
||||
protected ItemLayerModelBuilder(T parent, ExistingFileHelper existingFileHelper)
|
||||
@@ -116,6 +117,23 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
return renderType(asLoc, layers);
|
||||
}
|
||||
|
||||
public ItemLayerModelBuilder<T> renderType(String renderType, String renderTypeFast, int... layers)
|
||||
{
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
Preconditions.checkNotNull(renderTypeFast, "Fast graphics render type must not be null");
|
||||
ResourceLocation asLoc;
|
||||
if (renderType.contains(":"))
|
||||
asLoc = ResourceLocation.parse(renderType);
|
||||
else
|
||||
asLoc = parent.getLocation().withPath(renderType);
|
||||
ResourceLocation asLocFast;
|
||||
if (renderTypeFast.contains(":"))
|
||||
asLocFast = ResourceLocation.parse(renderTypeFast);
|
||||
else
|
||||
asLocFast = parent.getLocation().withPath(renderTypeFast);
|
||||
return renderType(asLoc, asLocFast, layers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the render type for a set of layers.
|
||||
*
|
||||
@@ -145,6 +163,25 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemLayerModelBuilder<T> renderType(ResourceLocation renderType, ResourceLocation renderTypeFast, int... layers)
|
||||
{
|
||||
Preconditions.checkNotNull(renderType, "Render type must not be null");
|
||||
Preconditions.checkNotNull(renderTypeFast, "Fast graphics render type must not be null");
|
||||
Preconditions.checkNotNull(layers, "Layers must not be null");
|
||||
Preconditions.checkArgument(layers.length > 0, "At least one layer must be specified");
|
||||
Preconditions.checkArgument(Arrays.stream(layers).allMatch(i -> i >= 0), "All layers must be >= 0");
|
||||
var alreadyAssigned = Arrays.stream(layers).filter(layersWithRenderTypes::contains).toArray();
|
||||
Preconditions.checkArgument(alreadyAssigned.length == 0, "Attempted to re-assign layer render types: " + Arrays.toString(alreadyAssigned));
|
||||
var renderTypeLayers = renderTypes.computeIfAbsent(renderType, $ -> new IntOpenHashSet());
|
||||
var renderTypeFastLayers = renderTypesFast.computeIfAbsent(renderType, $ -> new IntOpenHashSet());
|
||||
Arrays.stream(layers).forEach(layer -> {
|
||||
renderTypeLayers.add(layer);
|
||||
renderTypeFastLayers.add(layer);
|
||||
layersWithRenderTypes.add(layer);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJson(JsonObject json)
|
||||
{
|
||||
@@ -171,6 +208,14 @@ public class ItemLayerModelBuilder<T extends ModelBuilder<T>> extends CustomLoad
|
||||
});
|
||||
json.add("render_types", renderTypes);
|
||||
|
||||
JsonObject renderTypesFast = new JsonObject();
|
||||
this.renderTypesFast.forEach((renderTypeFast, layers) -> {
|
||||
JsonArray array = new JsonArray();
|
||||
layers.intStream().sorted().forEach(array::add);
|
||||
renderTypesFast.add(renderTypeFast.toString(), array);
|
||||
});
|
||||
json.add("render_types_fast", renderTypesFast);
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
+15
@@ -34,6 +34,8 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext {
|
||||
private Transformation rootTransform;
|
||||
@Nullable
|
||||
private ResourceLocation renderTypeHint;
|
||||
@Nullable
|
||||
private ResourceLocation renderTypeFastHint;
|
||||
private boolean gui3d = true;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@@ -115,10 +117,22 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext {
|
||||
return owner.parent != null ? owner.parent.customData.getRenderTypeHint() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getRenderTypeFastHint() {
|
||||
if (renderTypeFastHint != null)
|
||||
return renderTypeFastHint;
|
||||
return owner.parent != null ? owner.parent.customData.getRenderTypeFastHint() : null;
|
||||
}
|
||||
|
||||
public void setRenderTypeHint(ResourceLocation renderTypeHint) {
|
||||
this.renderTypeHint = renderTypeHint;
|
||||
}
|
||||
|
||||
public void setRenderTypeFastHint(ResourceLocation renderTypeFastHint) {
|
||||
this.renderTypeFastHint = renderTypeFastHint;
|
||||
}
|
||||
|
||||
public void setGui3d(boolean gui3d) {
|
||||
this.gui3d = gui3d;
|
||||
}
|
||||
@@ -128,6 +142,7 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext {
|
||||
this.rootTransform = other.rootTransform;
|
||||
this.visibilityData.copyFrom(other.visibilityData);
|
||||
this.renderTypeHint = other.renderTypeHint;
|
||||
this.renderTypeFastHint = other.renderTypeFastHint;
|
||||
this.gui3d = other.gui3d;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,13 @@ public interface IGeometryBakingContext {
|
||||
@Nullable
|
||||
ResourceLocation getRenderTypeHint();
|
||||
|
||||
/**
|
||||
* @return a hint of the {@linkplain net.minecraft.client.GraphicsStatus#FAST fast graphics} render type this model
|
||||
* should use. Custom loaders may ignore this.
|
||||
*/
|
||||
@Nullable
|
||||
default ResourceLocation getRenderTypeFastHint() { return null; }
|
||||
|
||||
/**
|
||||
* Queries the visibility of a component of this model.
|
||||
*
|
||||
@@ -89,4 +96,20 @@ public interface IGeometryBakingContext {
|
||||
default RenderTypeGroup getRenderType(ResourceLocation name) {
|
||||
return NamedRenderTypeManager.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a {@link RenderTypeGroup} from the {@link #getRenderTypeHint()}, or the empty group if not found.}
|
||||
*/
|
||||
default RenderTypeGroup getRenderType() {
|
||||
var hint = getRenderTypeHint();
|
||||
return hint == null ? RenderTypeGroup.EMPTY : getRenderType(hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a {@link RenderTypeGroup} from the {@link #getRenderTypeHint()}, or the empty group if not found.}
|
||||
*/
|
||||
default RenderTypeGroup getRenderTypeFast() {
|
||||
var hint = getRenderTypeFastHint();
|
||||
return hint == null ? RenderTypeGroup.EMPTY : getRenderType(hint);
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,8 @@ public abstract class SimpleUnbakedGeometry<T extends SimpleUnbakedGeometry<T>>
|
||||
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState) {
|
||||
TextureAtlasSprite particle = spriteGetter.apply(context.getMaterial("particle"));
|
||||
|
||||
var renderTypeHint = context.getRenderTypeHint();
|
||||
var renderTypes = renderTypeHint != null ? context.getRenderType(renderTypeHint) : RenderTypeGroup.EMPTY;
|
||||
IModelBuilder<?> builder = IModelBuilder.of(context.useAmbientOcclusion(), context.useBlockLight(), context.isGui3d(),
|
||||
context.getTransforms(), particle, renderTypes);
|
||||
context.getTransforms(), particle, context.getRenderType(), context.getRenderTypeFast());
|
||||
|
||||
addQuads(context, builder, baker, spriteGetter, modelState);
|
||||
|
||||
|
||||
+31
-1
@@ -51,6 +51,8 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
private final Transformation rootTransform;
|
||||
@Nullable
|
||||
private final ResourceLocation renderTypeHint;
|
||||
@Nullable
|
||||
private final ResourceLocation renderTypeFastHint;
|
||||
private final BiPredicate<String, Boolean> visibilityTest;
|
||||
|
||||
private StandaloneGeometryBakingContext(
|
||||
@@ -60,6 +62,18 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
ItemTransforms transforms, Transformation rootTransform,
|
||||
@Nullable ResourceLocation renderTypeHint,
|
||||
BiPredicate<String, Boolean> visibilityTest
|
||||
) {
|
||||
this(modelName, materialCheck, materialLookup, isGui3d, useBlockLight, useAmbientOcclusion, transforms, rootTransform, renderTypeHint, null, visibilityTest);
|
||||
}
|
||||
|
||||
private StandaloneGeometryBakingContext(
|
||||
ResourceLocation modelName, Predicate<String> materialCheck,
|
||||
Function<String, Material> materialLookup, boolean isGui3d,
|
||||
boolean useBlockLight, boolean useAmbientOcclusion,
|
||||
ItemTransforms transforms, Transformation rootTransform,
|
||||
@Nullable ResourceLocation renderTypeHint,
|
||||
@Nullable ResourceLocation renderTypeFastHint,
|
||||
BiPredicate<String, Boolean> visibilityTest
|
||||
) {
|
||||
this.modelName = modelName;
|
||||
this.materialCheck = materialCheck;
|
||||
@@ -70,6 +84,7 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
this.transforms = transforms;
|
||||
this.rootTransform = rootTransform;
|
||||
this.renderTypeHint = renderTypeHint;
|
||||
this.renderTypeFastHint = renderTypeFastHint;
|
||||
this.visibilityTest = visibilityTest;
|
||||
}
|
||||
|
||||
@@ -119,6 +134,12 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
return renderTypeHint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getRenderTypeFastHint() {
|
||||
return renderTypeFastHint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComponentVisible(String component, boolean fallback) {
|
||||
return visibilityTest.test(component, fallback);
|
||||
@@ -143,6 +164,8 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
private Transformation rootTransform = Transformation.identity();
|
||||
@Nullable
|
||||
private ResourceLocation renderTypeHint;
|
||||
@Nullable
|
||||
private ResourceLocation renderTypeFastHint;
|
||||
private BiPredicate<String, Boolean> visibilityTest = (c, def) -> def;
|
||||
|
||||
private Builder() { }
|
||||
@@ -156,6 +179,7 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
this.transforms = parent.getTransforms();
|
||||
this.rootTransform = parent.getRootTransform();
|
||||
this.renderTypeHint = parent.getRenderTypeHint();
|
||||
this.renderTypeFastHint = parent.getRenderTypeFastHint();
|
||||
this.visibilityTest = parent::isComponentVisible;
|
||||
}
|
||||
|
||||
@@ -205,6 +229,12 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRenderTypeHint(ResourceLocation renderTypeHint, ResourceLocation renderTypeFastHint) {
|
||||
this.renderTypeHint = renderTypeHint;
|
||||
this.renderTypeFastHint = renderTypeFastHint;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Builder withVisibleComponents(Object2BooleanMap<String> parts) {
|
||||
this.visibilityTest = parts::getOrDefault;
|
||||
@@ -212,7 +242,7 @@ public class StandaloneGeometryBakingContext implements IGeometryBakingContext {
|
||||
}
|
||||
|
||||
public StandaloneGeometryBakingContext build(ResourceLocation modelName) {
|
||||
return new StandaloneGeometryBakingContext(modelName, materialCheck, materialLookup, isGui3d, useBlockLight, useAmbientOcclusion, transforms, rootTransform, renderTypeHint, visibilityTest);
|
||||
return new StandaloneGeometryBakingContext(modelName, materialCheck, materialLookup, isGui3d, useBlockLight, useAmbientOcclusion, transforms, rootTransform, renderTypeHint, renderTypeFastHint, visibilityTest);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user