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-09-24 02:26:27 +02:00
|
|
|
package appeng.client.render;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.HashMap;
|
2015-09-16 18:03:07 +02:00
|
|
|
import java.util.Map;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
|
|
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.core.AELog;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
@SideOnly( Side.CLIENT )
|
2015-03-26 12:25:44 +01:00
|
|
|
public final class WorldRender implements ISimpleBlockRenderingHandler
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
public static final WorldRender INSTANCE = new WorldRender();
|
2015-09-16 18:03:07 +02:00
|
|
|
private final Map<AEBaseBlock, BaseBlockRender> blockRenders = new HashMap<AEBaseBlock, BaseBlockRender>();
|
2015-10-08 15:42:42 +02:00
|
|
|
private final int renderID = RenderingRegistry.getNextAvailableRenderId();
|
2015-04-03 08:54:31 +02:00
|
|
|
private final RenderBlocks renderer = new RenderBlocks();
|
2015-10-08 15:42:42 +02:00
|
|
|
private boolean hasError = false;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private WorldRender()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
void setRender( final AEBaseBlock in, final BaseBlockRender r )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
this.blockRenders.put( in, r );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderInventoryBlock( final Block block, final int metadata, final int modelID, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
// wtf is this for?
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean renderWorldBlock( final IBlockAccess world, final int x, final int y, final int z, final Block block, final int modelId, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEBaseBlock blk = (AEBaseBlock) block;
|
2014-09-24 02:26:27 +02:00
|
|
|
renderer.setRenderBoundsFromBlock( block );
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.getRender( blk ).renderInWorld( blk, world, x, y, z, renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean shouldRender3DInInventory( final int modelId )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRenderId()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.renderID;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private BaseBlockRender getRender( final AEBaseBlock block )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return block.getRendererInstance().getRendererInstance();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
void renderItemBlock( final ItemStack item, final ItemRenderType type, final Object[] data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Block blk = Block.getBlockFromItem( item.getItem() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( blk instanceof AEBaseBlock )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEBaseBlock block = (AEBaseBlock) blk;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderer.setRenderBoundsFromBlock( block );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderer.uvRotateBottom = this.renderer.uvRotateEast = this.renderer.uvRotateNorth = this.renderer.uvRotateSouth = this.renderer.uvRotateTop = this.renderer.uvRotateWest = 0;
|
|
|
|
this.getRender( block ).renderInventory( block, item, this.renderer, type, data );
|
|
|
|
this.renderer.uvRotateBottom = this.renderer.uvRotateEast = this.renderer.uvRotateNorth = this.renderer.uvRotateSouth = this.renderer.uvRotateTop = this.renderer.uvRotateWest = 0;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.hasError )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.hasError = true;
|
2014-09-24 02:26:27 +02:00
|
|
|
AELog.severe( "Invalid render - item/block mismatch" );
|
|
|
|
AELog.severe( " item: " + item.getUnlocalizedName() );
|
|
|
|
AELog.severe( " block: " + blk.getUnlocalizedName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|