use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class TileRenderSampleDrill method render.
@Override
public void render(TileEntitySampleDrill tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (tile.isDummy() || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
return;
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
BlockPos blockPos = tile.getPos();
IBakedModel model = blockRenderer.getModelForState(state);
if (state.getBlock() != IEContent.blockMetalDevice1)
return;
// .getModelFromBlockState(state, getWorld(), blockPos);
if (state instanceof IExtendedBlockState)
state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Lists.newArrayList("drill"), true));
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldRenderer = tessellator.getBuffer();
bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
if (Minecraft.isAmbientOcclusionEnabled())
GlStateManager.shadeModel(7425);
else
GlStateManager.shadeModel(7424);
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + .5, z + .5);
// float rot = 360*tile.rotation-(!tile.canTurn||tile.rotation==0||tile.rotation-tile.prevRotation<4?0:tile.facing.getAxis()==Axis.X?-f:f);
// GlStateManager.rotate(rot, 0,0,1);
int max = IEConfig.Machines.coredrill_time;
if (tile.process > 0 && tile.process < max) {
GlStateManager.rotate(((tile.process + partialTicks) * 22.5f) % 360f, 0, 1, 0);
float push = tile.process / (float) max;
if (tile.process > max / 2)
push = 1 - push;
GlStateManager.translate(0, -2.8f * push, 0);
}
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
worldRenderer.color(255, 255, 255, 255);
blockRenderer.getBlockModelRenderer().renderModel(tile.getWorld(), model, state, tile.getPos(), worldRenderer, true);
worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
tessellator.draw();
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class AttainedDropsHelper method init.
@Override
public void init() {
seed = ForgeRegistries.ITEMS.getValue(new ResourceLocation(AD_MODID, "seed"));
plant = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "plant"));
bulb = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "bulb"));
soil = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "soil"));
soilItem = Item.getItemFromBlock(soil);
addTypes();
BelljarHandler.registerHandler(new IPlantHandler() {
@Override
public boolean isCorrectSoil(ItemStack seed, ItemStack soil) {
return soil.getItem() == AttainedDropsHelper.this.soilItem && soil.getMetadata() > 0 && soil.getMetadata() <= 15;
}
@Override
public float getGrowthStep(ItemStack seed, ItemStack soil, float growth, TileEntity tile, float fertilizer, boolean render) {
return (growth < .5 ? .003125f : .0015625f) * fertilizer;
}
@Override
public float resetGrowth(ItemStack seed, ItemStack soil, float growth, TileEntity tile, boolean render) {
return .5f;
}
@Override
public ItemStack[] getOutput(ItemStack seed, ItemStack soil, TileEntity tile) {
ItemStack[] out = outputMap.get(soil.getMetadata());
if (out == null)
return new ItemStack[0];
return out;
}
@Override
public boolean isValid(ItemStack seed) {
return seed.getItem() == AttainedDropsHelper.this.seed;
}
@Override
@SideOnly(Side.CLIENT)
public IBlockState[] getRenderedPlant(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
return new IBlockState[0];
}
@Override
@SideOnly(Side.CLIENT)
public float getRenderSize(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
return .875f;
}
@Override
@SideOnly(Side.CLIENT)
public boolean overrideRender(ItemStack seed, ItemStack soil, float growth, TileEntity tile, BlockRendererDispatcher blockRenderer) {
IBlockState state = plant.getDefaultState().withProperty(BlockCrops.AGE, growth >= .5 ? 7 : Math.min(7, Math.round(7 * growth * 2)));
IBakedModel model = blockRenderer.getModelForState(state);
GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, 1);
blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
GlStateManager.popMatrix();
if (growth >= .5) {
state = bulbMap.get(soil.getMetadata());
model = blockRenderer.getModelForState(state);
if (model == null)
return false;
GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, 1);
float scale = (growth - .5f) * 2f;
GlStateManager.translate(.5 - scale / 2, 1, -.5 + scale / 2);
GlStateManager.scale(scale, scale, scale);
blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
GlStateManager.popMatrix();
}
return true;
}
});
}
use of net.minecraft.client.renderer.block.model.IBakedModel 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.IBakedModel 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.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method getSideTexture.
public static ResourceLocation getSideTexture(@Nonnull IBlockState state, EnumFacing side) {
IBakedModel model = mc().getBlockRendererDispatcher().getModelForState(state);
List<BakedQuad> quads = model.getQuads(state, side, 0);
if (// no quads for the specified side D:
quads == null || quads.isEmpty())
quads = model.getQuads(state, null, 0);
if (// no quads at all D:
quads == null || quads.isEmpty())
return null;
return new ResourceLocation(quads.get(0).getSprite().getIconName());
}
Aggregations