Skip to content

Commit

Permalink
Switch away from deprecated render layer setting (#8056)
Browse files Browse the repository at this point in the history
As NeoForge typically encourages the use of its own `render_type`
attribute to set render layers for block models while deprecating
`ItemBlockRenderTypes::setRenderLayer`, it may be a good idea to do the
same in AE2.

---------

Co-authored-by: Sebastian Hartte <[email protected]>
  • Loading branch information
62832 and shartte authored Jul 31, 2024
1 parent cfd9dbc commit ee6b391
Show file tree
Hide file tree
Showing 37 changed files with 74 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"parent": "minecraft:block/cross",
"render_type": "minecraft:cutout",
"textures": {
"cross": "ae2:block/large_quartz_bud"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"parent": "minecraft:block/cross",
"render_type": "minecraft:cutout",
"textures": {
"cross": "ae2:block/medium_quartz_bud"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"parent": "minecraft:block/cross",
"render_type": "minecraft:cutout",
"textures": {
"cross": "ae2:block/quartz_cluster"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"parent": "minecraft:block/cross",
"render_type": "minecraft:cutout",
"textures": {
"cross": "ae2:block/small_quartz_bud"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;

Expand All @@ -57,6 +58,8 @@ class PaintSplotchesBakedModel implements IDynamicBakedModel {
private static final Material TEXTURE_PAINT3 = new Material(TextureAtlas.LOCATION_BLOCKS,
AppEng.makeId("block/paint3"));

private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);

private final TextureAtlasSprite[] textures;

PaintSplotchesBakedModel(Function<Material, TextureAtlasSprite> bakedTextureGetter) {
Expand Down Expand Up @@ -188,4 +191,9 @@ public boolean usesBlockLight() {
static List<Material> getRequiredTextures() {
return ImmutableList.of(TEXTURE_PAINT1, TEXTURE_PAINT2, TEXTURE_PAINT3);
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
8 changes: 7 additions & 1 deletion src/main/java/appeng/block/qnb/QnbFormedBakedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;

Expand All @@ -48,7 +49,7 @@
import appeng.core.definitions.AEBlocks;

class QnbFormedBakedModel implements IDynamicBakedModel {

private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);
private static final Material TEXTURE_LINK = new Material(TextureAtlas.LOCATION_BLOCKS,
AppEng.makeId("block/quantum_link"));
private static final Material TEXTURE_RING = new Material(TextureAtlas.LOCATION_BLOCKS,
Expand Down Expand Up @@ -241,4 +242,9 @@ public static List<Material> getRequiredTextures() {
return ImmutableList.of(TEXTURE_LINK, TEXTURE_RING, TEXTURE_CABLE_GLASS, TEXTURE_COVERED_CABLE,
TEXTURE_RING_LIGHT, TEXTURE_RING_LIGHT_CORNER);
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.client.model.data.ModelProperty;
Expand Down Expand Up @@ -428,4 +429,8 @@ public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return ChunkRenderTypeSet.all();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.core.Direction.Axis;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;

Expand All @@ -46,6 +47,7 @@
* "inner" part of each block to the subclasses of this class.
*/
abstract class CraftingCubeBakedModel implements IDynamicBakedModel {
private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);

private final TextureAtlasSprite ringCorner;

Expand Down Expand Up @@ -267,4 +269,8 @@ public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
7 changes: 7 additions & 0 deletions src/main/java/appeng/client/render/model/DriveBakedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.data.ModelData;

import appeng.client.render.DelegateBakedModel;
import appeng.thirdparty.fabric.MutableQuadView;
import appeng.thirdparty.fabric.RenderContext;

public class DriveBakedModel extends DelegateBakedModel {
private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);
private final Map<Item, BakedModel> cellModels;
private final BakedModel defaultCellModel;

Expand Down Expand Up @@ -161,4 +163,9 @@ public boolean transform(MutableQuadView quad) {
return true;
}
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
6 changes: 6 additions & 0 deletions src/main/java/appeng/client/render/model/GlassBakedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;
import net.neoforged.neoforge.client.model.data.ModelProperty;
Expand All @@ -54,6 +55,7 @@
import appeng.decorative.solid.QuartzGlassBlock;

class GlassBakedModel implements IDynamicBakedModel {
private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);

// This unlisted property is used to determine the actual block that should be
// rendered
Expand Down Expand Up @@ -315,4 +317,8 @@ private static boolean isGlassBlock(BlockAndTintGetter level, BlockState state,
.getBlock() instanceof QuartzGlassBlock;
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.ChunkRenderTypeSet;
import net.neoforged.neoforge.client.model.IDynamicBakedModel;
import net.neoforged.neoforge.client.model.data.ModelData;

Expand All @@ -42,6 +43,7 @@
* The baked model that will be used for rendering the spatial pylon.
*/
class SpatialPylonBakedModel implements IDynamicBakedModel {
private static final ChunkRenderTypeSet RENDER_TYPES = ChunkRenderTypeSet.of(RenderType.CUTOUT);

private final Map<SpatialPylonTextureType, TextureAtlasSprite> textures;

Expand Down Expand Up @@ -199,4 +201,9 @@ public TextureAtlasSprite getParticleIcon() {
public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
}

@Override
public ChunkRenderTypeSet getRenderTypes(BlockState state, RandomSource rand, ModelData data) {
return RENDER_TYPES;
}
}
2 changes: 0 additions & 2 deletions src/main/java/appeng/core/AppEngClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import appeng.init.client.InitEntityLayerDefinitions;
import appeng.init.client.InitItemColors;
import appeng.init.client.InitItemModelsProperties;
import appeng.init.client.InitRenderTypes;
import appeng.init.client.InitScreens;
import appeng.init.client.InitStackRenderHandlers;
import appeng.items.storage.StorageCellTooltipComponent;
Expand Down Expand Up @@ -324,7 +323,6 @@ private void registerEntityLayerDefinitions(EntityRenderersEvent.RegisterLayerDe
private void postClientSetup(Minecraft minecraft) {
StyleManager.initialize(minecraft.getResourceManager());
InitStackRenderHandlers.init();
InitRenderTypes.init();

// Only activate the site exporter when we're not running a release version, since it'll
// replace blocks around spawn.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private void craftingModel(BlockDefinition<?> block, String name) {
private void generateQuartzCluster(BlockDefinition<?> quartz) {
var name = quartz.id().getPath();
var texture = makeId("block/" + name);
var model = models().cross(name, texture);
var model = models().cross(name, texture).renderType("cutout");
directionalBlock(quartz.block(), model);
itemModels().withExistingParent(name, mcLoc("item/generated")).texture("layer0", texture);
}
Expand Down
82 changes: 0 additions & 82 deletions src/main/java/appeng/init/client/InitRenderTypes.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/resources/assets/ae2/models/block/chest/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"details": "ae2:block/chest/details",
"particle": "ae2:block/chest/top_item"
},
"render_type": "cutout",
"elements": [
{
"from": [0, 7, 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"textures": {
"lights": "ae2:block/chest/lights_off"
},
"render_type": "cutout",
"elements": [
{
"from": [0, 0, 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lights_medium": "ae2:block/chest/lights_on_medium",
"lights_dark": "ae2:block/chest/lights_on_dark"
},
"render_type": "cutout",
"elements": [
{
"from": [0, 0, 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"textures": {
"particle": "ae2:block/controller"
},
"render_type": "cutout",
"elements": [
{
"faces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lights": "ae2:block/controller_column_conflict",
"particle": "ae2:block/controller"
},
"render_type": "cutout",
"elements": [
{
"faces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lights": "ae2:block/controller_column_lights",
"particle": "ae2:block/controller"
},
"render_type": "cutout",
"elements": [
{
"faces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"particle": "ae2:block/crg",
"base": "ae2:block/crg"
},
"render_type": "cutout",
"elements": [
{
"from": [4, 4, 4],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"particle": "ae2:block/molecular_assembler",
"base": "ae2:block/molecular_assembler"
},
"render_type": "cutout",
"elements": [
{
"from": [0, 0, 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"textures": {
"all": "ae2:block/molecular_assembler_lights"
},
"render_type": "cutout",
"elements": [
{
"from": [2, 2, 2],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"particle": "ae2:block/mysterious_cube_core",
"core": "ae2:block/mysterious_cube_core"
},
"render_type": "cutout",
"elements": [
{
"from": [0.01, 0.01, 0.01],
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/ae2/models/block/qnb/link.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"particle": "ae2:block/quantum_link",
"sides": "ae2:block/quantum_link"
},
"render_type": "cutout",
"elements": [
{
"from": [2, 2, 2],
Expand Down
Loading

0 comments on commit ee6b391

Please sign in to comment.