Applied-Energistics-2-tiler.../src/main/java/appeng/client/render/blocks/RenderBlockSkyChest.java

150 lines
4.8 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-02-28 09:12:00 +01:00
package appeng.client.render.blocks;
2015-09-30 14:25:28 +02:00
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.state.IBlockState;
2014-02-28 09:12:00 +01:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelChest;
2015-06-16 02:44:59 +02:00
import net.minecraft.client.renderer.WorldRenderer;
2014-02-28 09:12:00 +01:00
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
2014-02-28 09:12:00 +01:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import appeng.block.storage.BlockSkyChest;
2015-06-16 02:44:59 +02:00
import appeng.block.storage.BlockSkyChest.SkyChestType;
2016-01-01 01:47:22 +01:00
import appeng.client.ItemRenderType;
2014-02-28 09:12:00 +01:00
import appeng.client.render.BaseBlockRender;
2015-06-22 18:16:25 +02:00
import appeng.client.render.ModelGenerator;
2014-02-28 09:12:00 +01:00
import appeng.tile.storage.TileSkyChest;
public class RenderBlockSkyChest extends BaseBlockRender<BlockSkyChest, TileSkyChest>
2014-02-28 09:12:00 +01:00
{
2015-09-30 14:27:21 +02:00
private static final ResourceLocation SKY_STONE_CHEST = new ResourceLocation( "appliedenergistics2", "textures/models/skychest.png" );
private static final ResourceLocation SKY_BLOCK_CHEST = new ResourceLocation( "appliedenergistics2", "textures/models/skyblockchest.png" );
private static final ResourceLocation[] METADATA_TO_TEXTURE = { SKY_STONE_CHEST, SKY_BLOCK_CHEST };
private final ModelChest model = new ModelChest();
2014-02-28 09:12:00 +01:00
public RenderBlockSkyChest()
{
2014-02-28 09:12:00 +01:00
super( true, 80 );
}
@Override
2015-09-30 14:24:40 +02:00
public void renderInventory( final BlockSkyChest blk, final ItemStack is, final ModelGenerator renderer, final ItemRenderType type, final Object[] obj )
2014-02-28 09:12:00 +01:00
{
2015-12-24 02:03:16 +01:00
// GL11.glEnable( GL12.GL_RESCALE_NORMAL );
// GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
2014-02-28 09:12:00 +01:00
2015-12-24 02:03:16 +01:00
// final int metaData = is.getItemDamage();
// final ResourceLocation loc = METADATA_TO_TEXTURE[metaData];
2015-12-24 02:03:16 +01:00
// Minecraft.getMinecraft().getTextureManager().bindTexture( loc );
2014-02-28 09:12:00 +01:00
2015-12-24 02:03:16 +01:00
// final float lidAngle = 0.0f;
2014-02-28 09:12:00 +01:00
2015-12-24 02:03:16 +01:00
// GL11.glScalef( 1.0F, -1F, -1F );
// GL11.glTranslatef( -0.0F, -1.0F, -1.0F );
2014-02-28 09:12:00 +01:00
2015-12-24 02:03:16 +01:00
// this.model.chestLid.offsetY = -( 0.9f / 16.0f );
// this.model.chestLid.rotateAngleX = -( ( lidAngle * 3.141593F ) / 2.0F );
// this.model.renderAll();
2014-02-28 09:12:00 +01:00
2015-12-24 02:03:16 +01:00
// GL11.glDisable( GL12.GL_RESCALE_NORMAL );
// GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
2014-02-28 09:12:00 +01:00
}
@Override
2015-09-30 14:24:40 +02:00
public boolean renderInWorld( final BlockSkyChest blk, final IBlockAccess world, final BlockPos pos, final ModelGenerator renderer )
2014-02-28 09:12:00 +01:00
{
return true;
}
@Override
2015-09-30 14:24:40 +02:00
public void renderTile( final BlockSkyChest block, final TileSkyChest skyChest, final WorldRenderer tess, final double x, final double y, final double z, final float partialTick, final ModelGenerator renderer )
2014-02-28 09:12:00 +01:00
{
if( skyChest == null )
2015-04-29 02:30:53 +02:00
{
2014-02-28 09:12:00 +01:00
return;
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
if( !skyChest.hasWorldObj() )
2015-04-29 02:30:53 +02:00
{
2014-02-28 09:12:00 +01:00
return;
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
GL11.glEnable( GL12.GL_RESCALE_NORMAL );
2014-02-28 09:12:00 +01:00
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
2015-09-25 22:30:38 +02:00
final IBlockState metaData = skyChest.getWorld().getBlockState( skyChest.getPos() );
2015-12-24 02:03:16 +01:00
final ResourceLocation loc = METADATA_TO_TEXTURE[( (BlockSkyChest) metaData.getBlock() ).type == SkyChestType.BLOCK ? 1 : 0];
2014-02-28 09:12:00 +01:00
Minecraft.getMinecraft().getTextureManager().bindTexture( loc );
this.applyTESRRotation( x, y, z, skyChest.getForward(), skyChest.getUp() );
GL11.glScalef( 1.0F, -1F, -1F );
GL11.glTranslatef( -0.0F, -1.0F, -1.0F );
final long now = System.currentTimeMillis();
final long distance = now - skyChest.getLastEvent();
2014-02-28 09:12:00 +01:00
if( skyChest.getPlayerOpen() > 0 )
2015-04-29 02:30:53 +02:00
{
skyChest.setLidAngle( skyChest.getLidAngle() + distance * 0.0001f );
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
else
2015-04-29 02:30:53 +02:00
{
skyChest.setLidAngle( skyChest.getLidAngle() - distance * 0.0001f );
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
if( skyChest.getLidAngle() > 0.5f )
2015-04-29 02:30:53 +02:00
{
skyChest.setLidAngle( 0.5f );
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
if( skyChest.getLidAngle() < 0.0f )
2015-04-29 02:30:53 +02:00
{
skyChest.setLidAngle( 0.0f );
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
float lidAngle = skyChest.getLidAngle();
lidAngle = 1.0F - lidAngle;
lidAngle = 1.0F - lidAngle * lidAngle * lidAngle;
2014-02-28 09:12:00 +01:00
this.model.chestLid.offsetY = -( 1.01f / 16.0f );
this.model.chestLid.rotateAngleX = -( ( lidAngle * 3.141593F ) / 2.0F );
// The vanilla chests wants culling reversed...
GL11.glCullFace( GL11.GL_FRONT );
2014-12-29 15:13:47 +01:00
this.model.renderAll();
GL11.glCullFace( GL11.GL_BACK );
2014-02-28 09:12:00 +01:00
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
2014-02-28 09:12:00 +01:00
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
}
}