Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update model API #842

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/com/gtnewhorizons/angelica/common/BlockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class BlockTest extends Block implements ModeledBlock {
private QuadProvider model;

public BlockTest() {

super(Material.rock);
this.setBlockTextureName("missingno");
this.setModel((world, pos, block, meta, dir, random, color, quadPool) -> {
super(Material.wood);
setHardness(0.7f);
setBlockTextureName("missingno");
setModel((world, x, y, z, block, meta, dir, random, color, quadPool) -> {
if (meta < 2 || meta > 5) meta = 2;
return LECTERN.models[meta - 2].getQuads(world, pos, block, meta, dir, random, color, quadPool);
return LECTERN.models[meta - 2].getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
});
}

Expand Down
41 changes: 19 additions & 22 deletions src/main/java/com/gtnewhorizons/angelica/models/VanillaModels.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.gtnewhorizons.angelica.models;

import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
import com.gtnewhorizon.gtnhlib.blockpos.IBlockPos;
import com.gtnewhorizon.gtnhlib.client.model.ModelLoader;
import com.gtnewhorizon.gtnhlib.client.model.Variant;
import com.gtnewhorizon.gtnhlib.client.model.ModelVariant;
import com.gtnewhorizon.gtnhlib.client.model.json.ModelLocation;
import com.gtnewhorizon.gtnhlib.client.model.template.BlockColoredCube;
import com.gtnewhorizon.gtnhlib.client.model.template.BlockStaticCube;
Expand All @@ -12,13 +10,12 @@
import com.gtnewhorizon.gtnhlib.client.renderer.quad.QuadProvider;
import com.gtnewhorizon.gtnhlib.client.renderer.quad.QuadView;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;

public class VanillaModels {

Expand All @@ -33,37 +30,37 @@ public class VanillaModels {
public static BlockColoredCube JUNGLE_LEAVES;
public static QuadProvider OLD_LEAF = new QuadProvider() {
@Override
public int getColor(IBlockAccess world, IBlockPos pos, Block block, int meta, Random random) {
return QuadProvider.getDefaultColor(world, pos, block);
public int getColor(IBlockAccess world, int x, int y, int z, Block block, int meta, Random random) {
return QuadProvider.getDefaultColor(world, x, y, z, block);
}

@Override
public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
public List<QuadView> getQuads(IBlockAccess world, int x, int y, int z, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
return (switch (meta % 4) {
case 0 -> OAK_LEAVES;
case 1 -> SPRUCE_LEAVES;
case 2 -> BIRCH_LEAVES;
case 3 -> JUNGLE_LEAVES;
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}
};

public static BlockColoredCube ACACIA_LEAVES;
public static BlockColoredCube DARK_OAK_LEAVES;
public static QuadProvider NEW_LEAF = new QuadProvider() {
@Override
public int getColor(IBlockAccess world, IBlockPos pos, Block block, int meta, Random random) {
return QuadProvider.getDefaultColor(world, pos, block);
public int getColor(IBlockAccess world, int x, int y, int z, Block block, int meta, Random random) {
return QuadProvider.getDefaultColor(world, x, y, z, block);
}

@Override
public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
public List<QuadView> getQuads(IBlockAccess world, int x, int y, int z, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
return (switch (meta % 2) {
case 0 -> ACACIA_LEAVES;
case 1 -> DARK_OAK_LEAVES;
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}
};

Expand All @@ -77,7 +74,7 @@ public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, i
public static BlockStaticCube JUNGLE_WOOD;
public static QuadProvider OLD_LOG = new QuadProvider() {
@Override
public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
public List<QuadView> getQuads(IBlockAccess world, int x, int y, int z, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {

if (meta > 11) {
return (switch (meta) {
Expand All @@ -86,7 +83,7 @@ public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, i
case 14 -> BIRCH_WOOD;
case 15 -> JUNGLE_WOOD;
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}

Column3Rot ret = switch (meta % 4) {
Expand All @@ -102,7 +99,7 @@ public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, i
case 1 -> ret.eastwest();
case 2 -> ret.northsouth();
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}
};

Expand All @@ -112,14 +109,14 @@ public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, i
public static BlockStaticCube DARK_OAK_WOOD;
public static QuadProvider NEW_LOG = new QuadProvider() {
@Override
public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
public List<QuadView> getQuads(IBlockAccess world, int x, int y, int z, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {

if (meta > 11) {
return (switch (meta) {
case 12 -> ACACIA_WOOD;
case 13 -> DARK_OAK_WOOD;
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}

Column3Rot ret = switch (meta % 4) {
Expand All @@ -133,11 +130,11 @@ public List<QuadView> getQuads(IBlockAccess world, IBlockPos pos, Block block, i
case 1 -> ret.eastwest();
case 2 -> ret.northsouth();
default -> throw new IllegalStateException("Unexpected value: " + meta);
}).getQuads(world, pos, block, meta, dir, random, color, quadPool);
}).getQuads(world, x, y, z, block, meta, dir, random, color, quadPool);
}
};

public static final Variant workbench = new Variant(
public static final ModelVariant workbench = new ModelVariant(
new ModelLocation("block/crafting_table"),
0,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public boolean renderModel(IBlockAccess world, RenderBlocks renderBlocks, Block

if (model != null) {

final int color = model.getColor(world, pos, block, meta, random);
final int color = model.getColor(world, pos.x, pos.y, pos.z, block, meta, random);

for (ForgeDirection dir : DirectionUtil.ALL_DIRECTIONS) {

this.random.setSeed(seed);
List<QuadView> quads;

if (!cull || this.occlusionCache.shouldDrawSide(block, meta, world, pos, dir)) {
quads = model.getQuads(world, pos, block, meta, dir, random, color, this.quadPool::getInstance);
quads = model.getQuads(world, pos.x, pos.y, pos.z, block, meta, dir, random, color, this.quadPool::getInstance);
if (quads.isEmpty()) continue;

this.renderQuadList(pos, lighter, buffers, quads, ModelQuadFacing.fromDirection(dir), true);
Expand Down
Loading