use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class TileRenderBucketWheel method render.
@Override
public void render(TileEntityBucketWheel tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
return;
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
if (state.getBlock() != IEContent.blockMetalMultiblock)
return;
if (model == null) {
state = state.withProperty(IEProperties.DYNAMICRENDER, true);
state = state.withProperty(IEProperties.FACING_HORIZONTAL, EnumFacing.NORTH);
model = blockRenderer.getModelForState(state);
}
OBJState objState = null;
HashMap<String, String> texMap = new HashMap<>();
if (state instanceof IExtendedBlockState) {
ArrayList<String> list = Lists.newArrayList("bucketWheel");
synchronized (tile.digStacks) {
for (int i = 0; i < tile.digStacks.size(); i++) if (!tile.digStacks.get(i).isEmpty()) {
list.add("dig" + i);
Block b = Block.getBlockFromItem(tile.digStacks.get(i).getItem());
IBlockState digState = b != Blocks.AIR ? b.getStateFromMeta(tile.digStacks.get(i).getMetadata()) : Blocks.COBBLESTONE.getDefaultState();
IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
if (digModel != null && digModel.getParticleTexture() != null)
texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
}
}
objState = new OBJState(list, true);
}
Tessellator tessellator = Tessellator.getInstance();
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + .5, z + .5);
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
EnumFacing facing = tile.facing;
if (tile.mirrored) {
GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
GlStateManager.disableCull();
}
float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
GlStateManager.rotate(dir, 0, 1, 0);
float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * partialTicks : 0);
GlStateManager.rotate(rot, 1, 0, 0);
RenderHelper.disableStandardItemLighting();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
BufferBuilder worldRenderer = tessellator.getBuffer();
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
worldRenderer.setTranslation(-.5, -.5, -.5);
List<BakedQuad> quads;
if (model instanceof IESmartObjModel)
quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
else
quads = model.getQuads(state, null, 0);
ClientUtils.renderModelTESRFast(quads, worldRenderer, tile.getWorld(), tile.getPos());
worldRenderer.setTranslation(0, 0, 0);
tessellator.draw();
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
GlStateManager.disableBlend();
GlStateManager.enableCull();
if (tile.mirrored) {
GlStateManager.enableCull();
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ItemRendererIEOBJ method renderQuadsForGroups.
private void renderQuadsForGroups(String[] groups, IOBJModelCallback<ItemStack> callback, IESmartObjModel model, List<Pair<BakedQuad, ShaderLayer>> quadsForGroup, ItemStack stack, ShaderCase sCase, ItemStack shader, BufferBuilder bb, Tessellator tes, Map<String, Boolean> visible, float partialTicks) {
quadsForGroup.clear();
for (String g : groups) {
if (visible.getOrDefault(g, Boolean.FALSE) && callback.shouldRenderGroup(stack, g))
quadsForGroup.addAll(model.addQuadsForGroup(callback, stack, g, sCase, shader).stream().filter(Objects::nonNull).collect(Collectors.toList()));
visible.remove(g);
}
if (!callback.areGroupsFullbright(stack, groups))
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
else
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
VertexBufferConsumer vbc = new VertexBufferConsumer(bb);
ShaderLayer lastShaderLayer = null;
for (Pair<BakedQuad, ShaderLayer> pair : quadsForGroup) {
BakedQuad bq = pair.getKey();
ShaderLayer layer = pair.getValue();
// Switch to or between dynamic layers
boolean switchDynamic = layer != lastShaderLayer;
if (switchDynamic) {
// interrupt batch
tes.draw();
if (// finish dynamic call on last layer
lastShaderLayer != null)
lastShaderLayer.modifyRender(false, partialTicks);
// set new layer
lastShaderLayer = layer;
if (// start dynamic call on layer
lastShaderLayer != null)
lastShaderLayer.modifyRender(true, partialTicks);
// start new batch
if (!callback.areGroupsFullbright(stack, groups))
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
else
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
}
bq.pipe(vbc);
}
tes.draw();
if (// finish dynamic call on final layer
lastShaderLayer != null)
lastShaderLayer.modifyRender(false, partialTicks);
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ConveyorChute method modifyQuads.
@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
if (!initTextures) {
for (BlockTypes_MetalsAll metal : BlockTypes_MetalsAll.values()) TEXTURE_GETTERS[metal.getMeta()] = rl -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("immersiveengineering:blocks/sheetmetal_" + metal.getName());
initTextures = true;
}
if (this.sheetmetalType < 0 || this.sheetmetalType >= TEXTURE_GETTERS.length)
return baseModel;
Function<ResourceLocation, TextureAtlasSprite> textureGetter = TEXTURE_GETTERS[this.sheetmetalType];
if (chuteModel[this.sheetmetalType] == null)
try {
IModel iModel = ModelLoaderRegistry.getModel(new ResourceLocation("immersiveengineering:block/metal_device/chute.obj"));
chuteModel[this.sheetmetalType] = new IBakedModel[] { iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y180), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y0), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y90), DefaultVertexFormats.ITEM, textureGetter), iModel.bake(new OBJState(ImmutableList.of("base"), true, ModelRotation.X0_Y270), DefaultVertexFormats.ITEM, textureGetter) };
} catch (Exception ignored) {
}
float[] colour = { 1, 1, 1, 1 };
Matrix4 matrix = new Matrix4(facing);
baseModel.clear();
if (diagonal) {
IBlockState bs = tile != null && tile.getWorld() != null ? tile.getWorld().getBlockState(tile.getPos()) : IEContent.blockConveyor.getDefaultState();
if (chuteModel[this.sheetmetalType] != null && facing.ordinal() >= 2)
baseModel.addAll(chuteModel[this.sheetmetalType][facing.ordinal() - 2].getQuads(bs, null, 0));
} else {
Function<EnumFacing, TextureAtlasSprite> getSprite = f -> textureGetter.apply(null);
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, 0), new Vector3f(.0625f, 1, .0625f), matrix, facing, getSprite, colour));
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .9375f), new Vector3f(.0625f, 1, 1), matrix, facing, getSprite, colour));
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, 0), new Vector3f(1, 1, .0625f), matrix, facing, getSprite, colour));
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, .9375f), new Vector3f(1, 1, 1), matrix, facing, getSprite, colour));
if (renderWall(tile, EnumFacing.NORTH, facing))
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, 0, 0), new Vector3f(.9375f, 1, .0625f), matrix, facing, getSprite, colour));
if (renderWall(tile, EnumFacing.SOUTH, facing))
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.0625f, 0, .9375f), new Vector3f(.9375f, 1, 1), matrix, facing, getSprite, colour));
if (renderWall(tile, EnumFacing.WEST, facing))
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, 0, .0625f), new Vector3f(.0625f, 1, .9375f), matrix, facing, getSprite, colour));
if (renderWall(tile, EnumFacing.EAST, facing))
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, 0, .0625f), new Vector3f(1, 1, .9375f), matrix, facing, getSprite, colour));
}
return baseModel;
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ConveyorCovered method addCoverToQuads.
static void addCoverToQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing, Supplier<ItemStack> coverGet, ConveyorDirection conDir, boolean[] walls) {
ItemStack cover = !coverGet.get().isEmpty() ? coverGet.get() : defaultCover;
Block b = Block.getBlockFromItem(cover.getItem());
IBlockState state = !cover.isEmpty() ? b.getStateFromMeta(cover.getMetadata()) : Blocks.STONE.getDefaultState();
IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
if (model != null) {
TextureAtlasSprite sprite = model.getParticleTexture();
HashMap<EnumFacing, TextureAtlasSprite> sprites = new HashMap<>();
for (EnumFacing f : EnumFacing.VALUES) for (BakedQuad q : model.getQuads(state, f, 0)) if (q != null && q.getSprite() != null)
sprites.put(f, q.getSprite());
for (BakedQuad q : model.getQuads(state, null, 0)) if (q != null && q.getSprite() != null && q.getFace() != null)
sprites.put(q.getFace(), q.getSprite());
Function<EnumFacing, TextureAtlasSprite> getSprite = f -> sprites.containsKey(f) ? sprites.get(f) : sprite;
Function<EnumFacing, TextureAtlasSprite> getSpriteHorizontal = f -> f.getAxis() == Axis.Y ? null : sprites.containsKey(f) ? sprites.get(f) : sprite;
float[] colour = { 1, 1, 1, 1 };
Matrix4 matrix = new Matrix4(facing);
Function<Vector3f[], Vector3f[]> vertexTransformer = conDir == ConveyorDirection.HORIZONTAL ? vertices -> vertices : vertices -> {
Vector3f[] ret = new Vector3f[vertices.length];
for (int i = 0; i < ret.length; i++) ret[i] = new Vector3f(vertices[i].x, vertices[i].y + (vertices[i].z == (conDir == ConveyorDirection.UP ? 0 : 1) ? 1 : 0), vertices[i].z);
return ret;
};
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, 0), new Vector3f(1, 1, 1), matrix, facing, vertexTransformer, getSprite, colour));
if (walls[0])
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
else {
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
}
if (walls[1])
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
else {
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .9375f), new Vector3f(1, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
}
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class IESmartObjModel method getQuads.
public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand, OBJState objstate, Map<String, String> tex, boolean addAnimationAndTex) {
texReplace = tex;
this.tempState = blockState;
if (blockState instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) blockState;
ExtBlockstateAdapter adapter;
if (objstate != null) {
if (objstate.parent == null || objstate.parent == TRSRTransformation.identity())
objstate.parent = this.getState();
if (objstate.getVisibilityMap().containsKey(Group.ALL) || objstate.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
this.updateStateVisibilityMap(objstate);
}
if (addAnimationAndTex)
adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK, new Object[] { objstate, tex });
else
adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(), ExtBlockstateAdapter.CONNS_OBJ_CALLBACK);
List<BakedQuad> quads = modelCache.get(adapter);
if (quads == null) {
IESmartObjModel model = null;
if (objstate != null)
model = new IESmartObjModel(baseModel, getModel(), objstate, getFormat(), getTextures(), transformationMap, isDynamic);
if (model == null)
model = new IESmartObjModel(baseModel, getModel(), this.getState(), getFormat(), getTextures(), transformationMap, isDynamic);
model.tempState = blockState;
model.texReplace = tex;
quads = model.buildQuads();
modelCache.put(adapter, quads);
}
return Collections.synchronizedList(Lists.newArrayList(quads));
}
if (bakedQuads == null)
bakedQuads = buildQuads();
List<BakedQuad> quadList = Lists.newArrayList(bakedQuads);
return Collections.synchronizedList(quadList);
}
Aggregations