Fixes #2429: Inscriber TESR
This commit is contained in:
@@ -22,8 +22,10 @@ package appeng.block.misc;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumBlockRenderType;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -67,6 +69,12 @@ public class BlockInscriber extends AEBaseTileBlock
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumBlockRenderType getRenderType( IBlockState state )
|
||||||
|
{
|
||||||
|
return EnumBlockRenderType.MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName( final ItemStack is )
|
public String getUnlocalizedName( final ItemStack is )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package appeng.block.misc;
|
||||||
|
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
import appeng.bootstrap.BlockRenderingCustomizer;
|
||||||
|
import appeng.bootstrap.IBlockRendering;
|
||||||
|
import appeng.bootstrap.IItemRendering;
|
||||||
|
import appeng.client.render.tesr.InscriberTESR;
|
||||||
|
|
||||||
|
|
||||||
|
public class InscriberRendering extends BlockRenderingCustomizer
|
||||||
|
{
|
||||||
|
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
@Override
|
||||||
|
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||||
|
{
|
||||||
|
rendering.tesr( new InscriberTESR() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -52,6 +52,7 @@ import appeng.client.render.effects.LightningArcFX;
|
|||||||
import appeng.client.render.effects.LightningFX;
|
import appeng.client.render.effects.LightningFX;
|
||||||
import appeng.client.render.effects.VibrantFX;
|
import appeng.client.render.effects.VibrantFX;
|
||||||
import appeng.client.render.model.UVLModelLoader;
|
import appeng.client.render.model.UVLModelLoader;
|
||||||
|
import appeng.client.render.tesr.InscriberTESR;
|
||||||
import appeng.client.render.textures.ParticleTextures;
|
import appeng.client.render.textures.ParticleTextures;
|
||||||
import appeng.core.AEConfig;
|
import appeng.core.AEConfig;
|
||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
@@ -361,5 +362,6 @@ public class ClientHelper extends ServerHelper
|
|||||||
public void onTextureStitch( final TextureStitchEvent.Pre event )
|
public void onTextureStitch( final TextureStitchEvent.Pre event )
|
||||||
{
|
{
|
||||||
ParticleTextures.registerSprite( event );
|
ParticleTextures.registerSprite( event );
|
||||||
|
InscriberTESR.registerTexture( event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
package appeng.client.render.tesr;
|
||||||
|
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.VertexBuffer;
|
||||||
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
|
|
||||||
|
import appeng.api.features.IInscriberRecipe;
|
||||||
|
import appeng.client.render.FacingToRotation;
|
||||||
|
import appeng.core.AELog;
|
||||||
|
import appeng.core.AppEng;
|
||||||
|
import appeng.tile.AEBaseTile;
|
||||||
|
import appeng.tile.misc.TileInscriber;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the dynamic parts of an inscriber (the presses, the animation and the item being smashed)
|
||||||
|
*/
|
||||||
|
public class InscriberTESR extends TileEntitySpecialRenderer<TileInscriber>
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final float ITEM_RENDER_SCALE = 1.0f / 1.2f;
|
||||||
|
|
||||||
|
private static final ResourceLocation TEXTURE_INSIDE = new ResourceLocation( AppEng.MOD_ID, "blocks/inscriber_inside" );
|
||||||
|
|
||||||
|
private static TextureAtlasSprite textureInside;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderTileEntityAt( TileInscriber tile, double x, double y, double z, float partialTicks, int destroyStage )
|
||||||
|
{
|
||||||
|
// render inscriber
|
||||||
|
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.translate( x, y, z );
|
||||||
|
GlStateManager.translate( 0.5F, 0.5F, 0.5F );
|
||||||
|
FacingToRotation.get( tile.getForward(), tile.getUp() ).glRotateCurrentMat();
|
||||||
|
GlStateManager.translate( -0.5F, -0.5F, -0.5F );
|
||||||
|
|
||||||
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
|
GlStateManager.disableLighting();
|
||||||
|
GlStateManager.disableRescaleNormal();
|
||||||
|
|
||||||
|
// render sides of stamps
|
||||||
|
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
mc.renderEngine.bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||||
|
|
||||||
|
// << 20 | light << 4;
|
||||||
|
final int br = tile.getWorld().getCombinedLight( tile.getPos(), 0 );
|
||||||
|
final int var11 = br % 65536;
|
||||||
|
final int var12 = br / 65536;
|
||||||
|
|
||||||
|
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11, var12 );
|
||||||
|
|
||||||
|
long absoluteProgress = 0;
|
||||||
|
|
||||||
|
if( tile.isSmash() )
|
||||||
|
{
|
||||||
|
final long currentTime = System.currentTimeMillis();
|
||||||
|
absoluteProgress = currentTime - tile.getClientStart();
|
||||||
|
if( absoluteProgress > 800 )
|
||||||
|
{
|
||||||
|
tile.setSmash( false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final float relativeProgress = absoluteProgress % 800 / 400.0f;
|
||||||
|
float progress = relativeProgress;
|
||||||
|
|
||||||
|
if( progress > 1.0f )
|
||||||
|
{
|
||||||
|
progress = 1.0f - ( progress - 1.0f );
|
||||||
|
}
|
||||||
|
float press = 0.2f;
|
||||||
|
press -= progress / 5.0f;
|
||||||
|
|
||||||
|
VertexBuffer buffer = Tessellator.getInstance().getBuffer();
|
||||||
|
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
||||||
|
|
||||||
|
float middle = 0.5f;
|
||||||
|
middle += 0.02f;
|
||||||
|
final float TwoPx = 2.0f / 16.0f;
|
||||||
|
final float base = 0.4f;
|
||||||
|
|
||||||
|
final TextureAtlasSprite tas = textureInside;
|
||||||
|
if( tas != null )
|
||||||
|
{
|
||||||
|
// Bottom of Top Stamp
|
||||||
|
buffer.pos( TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 13 ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 13 ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle + press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 2 ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle + press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 2 ) ).endVertex();
|
||||||
|
|
||||||
|
// Front of Top Stamp
|
||||||
|
buffer.pos( TwoPx, middle + base, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle + base, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 ) ).endVertex();
|
||||||
|
|
||||||
|
// Top of Bottom Stamp
|
||||||
|
middle -= 2.0f * 0.02f;
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 13 ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 13 ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle - press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 2 ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle - press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 2 ) ).endVertex();
|
||||||
|
|
||||||
|
// Front of Bottom Stamp
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle + -base, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle - base, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex();
|
||||||
|
buffer.pos( TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 ) ).endVertex();
|
||||||
|
buffer.pos( 1.0 - TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 ) ).endVertex();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tessellator.getInstance().draw();
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
|
||||||
|
// render items.
|
||||||
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
|
|
||||||
|
int items = 0;
|
||||||
|
if( tile.getStackInSlot( 0 ) != null )
|
||||||
|
{
|
||||||
|
items++;
|
||||||
|
}
|
||||||
|
if( tile.getStackInSlot( 1 ) != null )
|
||||||
|
{
|
||||||
|
items++;
|
||||||
|
}
|
||||||
|
if( tile.getStackInSlot( 2 ) != null )
|
||||||
|
{
|
||||||
|
items++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.ITEM );
|
||||||
|
|
||||||
|
if( relativeProgress > 1.0f || items == 0 )
|
||||||
|
{
|
||||||
|
ItemStack is = tile.getStackInSlot( 3 );
|
||||||
|
|
||||||
|
if( is == null )
|
||||||
|
{
|
||||||
|
final IInscriberRecipe ir = tile.getTask();
|
||||||
|
if( ir != null )
|
||||||
|
{
|
||||||
|
is = ir.getOutput().copy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderItem( is, 0.0f, tile, buffer, x, y, z );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.renderItem( tile.getStackInSlot( 0 ), press, tile, buffer, x, y, z );
|
||||||
|
this.renderItem( tile.getStackInSlot( 1 ), -press, tile, buffer, x, y, z );
|
||||||
|
this.renderItem( tile.getStackInSlot( 2 ), 0.0f, tile, buffer, x, y, z );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tessellator.getInstance().draw();
|
||||||
|
|
||||||
|
GlStateManager.enableLighting();
|
||||||
|
GlStateManager.enableRescaleNormal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderItem( ItemStack sis, final float o, final AEBaseTile tile, final VertexBuffer tess, final double x, final double y, final double z )
|
||||||
|
{
|
||||||
|
if( sis != null )
|
||||||
|
{
|
||||||
|
sis = sis.copy();
|
||||||
|
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
|
||||||
|
GlStateManager.translate( x, y, z );
|
||||||
|
GlStateManager.translate( 0.5F, 0.5F, 0.5F );
|
||||||
|
FacingToRotation.get( tile.getForward(), tile.getUp() ).glRotateCurrentMat();
|
||||||
|
GlStateManager.translate( -0.5F, -0.5F, -0.5F );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// move to center
|
||||||
|
GlStateManager.translate( 0.5f, 0.5f + o, 0.5f );
|
||||||
|
|
||||||
|
GlStateManager.rotate( 90, 1, 0, 0 );
|
||||||
|
|
||||||
|
// set scale
|
||||||
|
GlStateManager.scale( ITEM_RENDER_SCALE, ITEM_RENDER_SCALE, ITEM_RENDER_SCALE );
|
||||||
|
|
||||||
|
// heuristic to scale items down much further than blocks
|
||||||
|
final Block blk = Block.getBlockFromItem( sis.getItem() );
|
||||||
|
if( blk == null )
|
||||||
|
{
|
||||||
|
GlStateManager.scale( 0.5, 0.5, 0.5 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// << 20 | light << 4;
|
||||||
|
final int br = tile.getWorld().getCombinedLight( tile.getPos(), 0 );
|
||||||
|
final int var11 = br % 65536;
|
||||||
|
final int var12 = br / 65536;
|
||||||
|
|
||||||
|
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11, var12 );
|
||||||
|
|
||||||
|
Minecraft.getMinecraft().getRenderItem().renderItem( sis, ItemCameraTransforms.TransformType.FIXED );
|
||||||
|
}
|
||||||
|
catch( final Exception err )
|
||||||
|
{
|
||||||
|
AELog.debug( err );
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTexture( TextureStitchEvent.Pre event )
|
||||||
|
{
|
||||||
|
textureInside = event.getMap().registerSprite( TEXTURE_INSIDE );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ import appeng.block.misc.BlockSecurityStation;
|
|||||||
import appeng.block.misc.BlockSkyCompass;
|
import appeng.block.misc.BlockSkyCompass;
|
||||||
import appeng.block.misc.BlockTinyTNT;
|
import appeng.block.misc.BlockTinyTNT;
|
||||||
import appeng.block.misc.BlockVibrationChamber;
|
import appeng.block.misc.BlockVibrationChamber;
|
||||||
|
import appeng.block.misc.InscriberRendering;
|
||||||
import appeng.block.misc.SecurityStationRendering;
|
import appeng.block.misc.SecurityStationRendering;
|
||||||
import appeng.block.misc.SkyCompassRendering;
|
import appeng.block.misc.SkyCompassRendering;
|
||||||
import appeng.block.networking.BlockCableBus;
|
import appeng.block.networking.BlockCableBus;
|
||||||
@@ -253,7 +254,10 @@ public final class ApiBlocks implements IBlocks
|
|||||||
.features( AEFeature.GrindStone )
|
.features( AEFeature.GrindStone )
|
||||||
.rendering( new CrankRendering() )
|
.rendering( new CrankRendering() )
|
||||||
.build();
|
.build();
|
||||||
this.inscriber = registry.block( "inscriber", BlockInscriber::new ).features( AEFeature.Inscriber ).build();
|
this.inscriber = registry.block( "inscriber", BlockInscriber::new )
|
||||||
|
.features( AEFeature.Inscriber )
|
||||||
|
.rendering( new InscriberRendering() )
|
||||||
|
.build();
|
||||||
this.wirelessAccessPoint = registry.block( "wireless_access_point", BlockWireless::new ).features( AEFeature.WirelessAccessTerminal ).build();
|
this.wirelessAccessPoint = registry.block( "wireless_access_point", BlockWireless::new ).features( AEFeature.WirelessAccessTerminal ).build();
|
||||||
this.charger = registry.block( "charger", BlockCharger::new )
|
this.charger = registry.block( "charger", BlockCharger::new )
|
||||||
.rendering( new BlockRenderingCustomizer()
|
.rendering( new BlockRenderingCustomizer()
|
||||||
|
|||||||
Reference in New Issue
Block a user