Implemented modular TESR

-Implemented modular TERS.
-Added ItemRenderable, charger example attached.
This commit is contained in:
elix-x 2016-07-12 20:03:54 +02:00
parent 524dc52dd6
commit 7a653675de
6 changed files with 140 additions and 5 deletions

View file

@ -26,9 +26,14 @@ import java.util.Random;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -44,6 +49,8 @@ import appeng.api.AEApi;
import appeng.api.util.AEAxisAlignedBB;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.effects.LightningFX;
import appeng.client.render.renderable.ItemRenderable;
import appeng.client.render.tesr.ModularTESR;
import appeng.core.AEConfig;
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
@ -123,6 +130,13 @@ public class BlockCharger extends AEBaseTileBlock implements ICustomCollision
}
}
@Override
@SideOnly( Side.CLIENT )
public TileEntitySpecialRenderer<TileCharger> getTESR()
{
return new ModularTESR( new ItemRenderable<TileCharger>( tile -> new ImmutablePair( tile.getStackInSlot( 0 ), new Matrix4f().translate( new Vector3f( 0.5f, 0.4f, 0.5f ) ) ) ) );
}
@Override
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( final World w, final BlockPos pos, final Entity thePlayer, final boolean b )
{

View file

@ -0,0 +1,55 @@
package appeng.client.render.renderable;
import java.nio.FloatBuffer;
import java.util.function.Function;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.vector.Matrix4f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class ItemRenderable<T extends TileEntity> implements Renderable<T>
{
private final Function<T, Pair<ItemStack, Matrix4f>> f;
public ItemRenderable( Function<T, Pair<ItemStack, Matrix4f>> f )
{
this.f = f;
}
@Override
public void renderTileEntityAt( T te, double x, double y, double z, float partialTicks, int destroyStage )
{
Pair<ItemStack, Matrix4f> pair = f.apply( te );
if( pair != null && pair.getLeft() != null )
{
GlStateManager.pushMatrix();
if( pair.getRight() != null )
{
FloatBuffer matrix = BufferUtils.createFloatBuffer( 16 );
pair.getRight().store( matrix );
matrix.flip();
GlStateManager.multMatrix( matrix );
}
Minecraft.getMinecraft().getRenderItem().renderItem( pair.getLeft(), TransformType.GROUND );
GlStateManager.popMatrix();
}
}
@Override
public void renderTileEntityFast( T te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer buffer )
{
}
}

View file

@ -0,0 +1,16 @@
package appeng.client.render.renderable;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.tileentity.TileEntity;
public interface Renderable<T extends TileEntity>
{
public void renderTileEntityAt( T te, double x, double y, double z, float partialTicks, int destroyStage );
public void renderTileEntityFast( T te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer buffer );
}

View file

@ -0,0 +1,54 @@
package appeng.client.render.tesr;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import appeng.client.render.FacingToRotation;
import appeng.client.render.renderable.Renderable;
import appeng.tile.AEBaseTile;
public class ModularTESR<T extends AEBaseTile> extends TileEntitySpecialRenderer<T>
{
private final Renderable[] renderables;
public ModularTESR( Renderable... renderables )
{
this.renderables = renderables;
}
@Override
public void renderTileEntityAt( T te, double x, double y, double z, float partialTicks, int destroyStage )
{
GlStateManager.pushMatrix();
GlStateManager.translate( x, y, z );
GlStateManager.translate( 0.5, 0.5, 0.5 );
FacingToRotation.get( te.getForward(), te.getUp() ).glRotateCurrentMat();
GlStateManager.translate( -0.5, -0.5, -0.5 );
for( Renderable renderable : renderables )
{
renderable.renderTileEntityAt( te, x, y, z, partialTicks, destroyStage );
}
GlStateManager.popMatrix();
}
@Override
public void renderTileEntityFast( T te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer buffer )
{
GlStateManager.pushMatrix();
GlStateManager.translate( x, y, z );
GlStateManager.translate( 0.5, 0.5, 0.5 );
FacingToRotation.get( te.getForward(), te.getUp() ).glRotateCurrentMat();
GlStateManager.translate( -0.5, -0.5, -0.5 );
for( Renderable renderable : renderables )
{
renderable.renderTileEntityFast( te, x, y, z, partialTicks, destroyStage, buffer );
}
GlStateManager.popMatrix();
}
}

View file

@ -1,8 +1,5 @@
{
"variants": {
"forward=north": { "model": "appliedenergistics2:tile.BlockCharger", "y": 180 },
"forward=south": { "model": "appliedenergistics2:tile.BlockCharger", "y": 0 },
"forward=east": { "model": "appliedenergistics2:tile.BlockCharger", "y": 90 },
"forward=west": { "model": "appliedenergistics2:tile.BlockCharger", "y": 270 }
"normal": { "model": "appliedenergistics2:tile.BlockCharger" }
}
}