Moved F2R, added TESRs, fixed culling

-Externalized FacingToRotation.
-BlockLightDetector now uses tile based rotations.
-Added TESR methods and TESRs for chests. Can't get it to work in
inventory.
-Fixed rotation bugs involving culling and lighting. Now rotating culled
faces and normals too. Closes #21.
Relates to #9, #10 and #20.
This commit is contained in:
elix-x 2016-07-11 15:38:54 +02:00
parent d64a63992c
commit 524dc52dd6
12 changed files with 415 additions and 134 deletions

View file

@ -34,8 +34,8 @@ import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@ -49,10 +49,8 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
@ -86,29 +84,40 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements IAEFeature,
{
super( mat, subName );
}
public static final PropertyDirection AE_BLOCK_FORWARD = PropertyDirection.create( "forward" );
public static final PropertyDirection AE_BLOCK_UP = PropertyDirection.create( "up" );
@Override
protected IProperty[] getAEStates()
{
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP };
}
@Override
public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos )
{
AEBaseTile tile = (AEBaseTile) world.getTileEntity( pos );
return super.getActualState( state, world, pos ).withProperty( AE_BLOCK_FORWARD, tile.getForward()).withProperty( AE_BLOCK_UP, tile.getUp() );
return super.getActualState( state, world, pos ).withProperty( AE_BLOCK_FORWARD, tile.getForward() ).withProperty( AE_BLOCK_UP, tile.getUp() );
}
@Override
public int getMetaFromState( IBlockState state )
{
return 0;
}
@SideOnly( Side.CLIENT )
public TileEntitySpecialRenderer<? extends AEBaseTile> getTESR()
{
return null;
}
public boolean hasItemTESR()
{
return false;
}
@Override
protected void setFeature( final EnumSet<AEFeature> f )
{
@ -120,13 +129,12 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements IAEFeature,
{
this.tileEntityType = c;
this.setInventory( IInventory.class.isAssignableFrom( c ) );
this.setTileProvider( this.hasBlockTileEntity() );
}
// update Block value.
private void setTileProvider( final boolean b )
@Override
public boolean hasTileEntity( IBlockState state )
{
ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" );
return hasBlockTileEntity();
}
private boolean hasBlockTileEntity()
@ -134,7 +142,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements IAEFeature,
return this.tileEntityType != null;
}
public Class<? extends TileEntity> getTileEntityClass()
public Class<? extends AEBaseTile> getTileEntityClass()
{
return this.tileEntityType;
}
@ -283,7 +291,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements IAEFeature,
{
if( Platform.isWrench( player, heldItem, pos ) && player.isSneaking() )
{
final IBlockState ids = w.getBlockState( pos );
final IBlockState ids = w.getBlockState( pos );
final Block id = ids.getBlock();
if( id != null )
{

View file

@ -60,23 +60,10 @@ public class BlockLightDetector extends AEBaseTileBlock implements IOrientableBl
this.setFeature( EnumSet.of( AEFeature.LightDetector ) );
}
@Override
public int getMetaFromState( final IBlockState state )
{
return 0;
}
@Override
public IBlockState getStateFromMeta( final int meta )
{
return this.getDefaultState();
}
@Override
protected IProperty[] getAEStates()
{
//TODO 1.10-R - wtf?
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP, BlockTorch.FACING };
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP };
}
@Override
@ -173,12 +160,7 @@ public class BlockLightDetector extends AEBaseTileBlock implements IOrientableBl
@Override
public boolean usesMetadata()
{
return true;
return false;
}
@Override
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
{
return new MetaRotation( w, pos, true );
}
}

View file

@ -28,17 +28,23 @@ import javax.annotation.Nullable;
import com.google.common.base.Optional;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.tesr.SkyChestTESR;
import appeng.core.features.AEFeature;
import appeng.core.sync.GuiBridge;
import appeng.helpers.ICustomCollision;
@ -69,6 +75,25 @@ public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision
this.setFeature( EnumSet.of( AEFeature.Core, AEFeature.SkyStoneChests ) );
}
@Override
public EnumBlockRenderType getRenderType( IBlockState state )
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
@SideOnly( Side.CLIENT )
public TileEntitySpecialRenderer<TileSkyChest> getTESR()
{
return new SkyChestTESR();
}
@Override
public boolean hasItemTESR()
{
return true;
}
@Override
public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{

View file

@ -0,0 +1,104 @@
package appeng.client.render;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.model.TRSRTransformation;
public enum FacingToRotation
{
// DUNSWE
//@formatter:off
DOWN_DOWN ( new Vector3f( 0, 0, 0 ) ), //NOOP
DOWN_UP ( new Vector3f( 0, 0, 0 ) ), //NOOP
DOWN_NORTH ( new Vector3f( -90, 0, 0 ) ),
DOWN_SOUTH ( new Vector3f( -90, 0, 180 ) ),
DOWN_WEST ( new Vector3f( -90, 0, 90 ) ),
DOWN_EAST ( new Vector3f( -90, 0, -90 ) ),
UP_DOWN ( new Vector3f( 0, 0, 0 ) ), //NOOP
UP_UP ( new Vector3f( 0, 0, 0 ) ), //NOOP
UP_NORTH ( new Vector3f( 90, 0, 180 ) ),
UP_SOUTH ( new Vector3f( 90, 0, 0 ) ),
UP_WEST ( new Vector3f( 90, 0, 90 ) ),
UP_EAST ( new Vector3f( 90, 0, -90 ) ),
NORTH_DOWN ( new Vector3f( 0, 0, 180 ) ),
NORTH_UP ( new Vector3f( 0, 0, 0 ) ),
NORTH_NORTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
NORTH_SOUTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
NORTH_WEST ( new Vector3f( 0, 0, 90 ) ),
NORTH_EAST ( new Vector3f( 0, 0, -90 ) ),
SOUTH_DOWN ( new Vector3f( 0, 180, 180 ) ),
SOUTH_UP ( new Vector3f( 0, 180, 0 ) ),
SOUTH_NORTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
SOUTH_SOUTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
SOUTH_WEST ( new Vector3f( 0, 180, -90 ) ),
SOUTH_EAST ( new Vector3f( 0, 180, 90 ) ),
WEST_DOWN ( new Vector3f( 0, 90, 180 ) ),
WEST_UP ( new Vector3f( 0, 90, 0 ) ),
WEST_NORTH ( new Vector3f( 0, 90, -90 ) ),
WEST_SOUTH ( new Vector3f( 0, 90, 90 ) ),
WEST_WEST ( new Vector3f( 0, 0, 0 ) ), //NOOP
WEST_EAST ( new Vector3f( 0, 0, 0 ) ), //NOOP
EAST_DOWN ( new Vector3f( 0, -90, 180 ) ),
EAST_UP ( new Vector3f( 0, -90, 0 ) ),
EAST_NORTH ( new Vector3f( 0, -90, 90 ) ),
EAST_SOUTH ( new Vector3f( 0, -90, -90 ) ),
EAST_WEST ( new Vector3f( 0, 0, 0 ) ), //NOOP
EAST_EAST ( new Vector3f( 0, 0, 0 ) ); //NOOP
//@formatter:on
private final Vector3f rot;
private final Matrix4f mat;
private FacingToRotation( Vector3f rot )
{
this.rot = rot;
this.mat = TRSRTransformation.toVecmath( new org.lwjgl.util.vector.Matrix4f().rotate( (float) Math.toRadians( rot.x ), new org.lwjgl.util.vector.Vector3f( 1, 0, 0 ) ).rotate( (float) Math.toRadians( rot.y ), new org.lwjgl.util.vector.Vector3f( 0, 1, 0 ) ).rotate( (float) Math.toRadians( rot.z ), new org.lwjgl.util.vector.Vector3f( 0, 0, 1 ) ) );
}
public Vector3f getRot()
{
return rot;
}
public Matrix4f getMat()
{
return new Matrix4f( this.mat );
}
public void glRotateCurrentMat()
{
GlStateManager.rotate( rot.x, 1, 0, 0 );
GlStateManager.rotate( rot.y, 0, 1, 0 );
GlStateManager.rotate( rot.z, 0, 0, 1 );
}
public EnumFacing rotate( EnumFacing facing )
{
return TRSRTransformation.rotate( mat, facing );
}
public EnumFacing resultingRotate( EnumFacing facing )
{
for( EnumFacing face : EnumFacing.values() )
{
if( rotate( face ) == facing )
{
return face;
}
}
return null;
}
public static FacingToRotation get( EnumFacing forward, EnumFacing up )
{
return values()[forward.ordinal() * 6 + up.ordinal()];
}
}

View file

@ -40,6 +40,8 @@ public class AEIgnoringStateMapper extends StateMapperBase implements IResourceM
try
{
ignored.clear();
ignored.add( "forward" );
ignored.add( "up" );
ignored.addAll( IOUtils.readLines( resourceManager.getResource( ignoredRL ).getInputStream() ) );
}
catch( IOException e )

View file

@ -5,7 +5,6 @@ package appeng.client.render.model;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
@ -26,12 +25,13 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3i;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
import net.minecraftforge.common.model.TRSRTransformation;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.FacingToRotation;
public class CachingRotatingBakedModel implements IBakedModel
@ -51,18 +51,20 @@ public class CachingRotatingBakedModel implements IBakedModel
{
final EnumFacing forward = key.getLeft().getValue( AEBaseTileBlock.AE_BLOCK_FORWARD );
final EnumFacing up = key.getLeft().getValue( AEBaseTileBlock.AE_BLOCK_UP );
final Matrix4f mat = FacingToRotation.get( forward, up ).getMat();
final FacingToRotation f2r = FacingToRotation.get( forward, up );
List<BakedQuad> original = CachingRotatingBakedModel.this.parent.getQuads( key.getLeft(), key.getRight(), 0 );
List<BakedQuad> original = CachingRotatingBakedModel.this.parent.getQuads( key.getLeft(), f2r.resultingRotate( key.getRight() ), 0 );
List<BakedQuad> rotated = new ArrayList<>();
for( BakedQuad quad : original )
{
VertexFormat format = quad.getFormat();
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder( format );
VertexRotator rot = new VertexRotator( mat );
VertexRotator rot = new VertexRotator( f2r, quad.getFace() );
rot.setParent( builder );
quad.pipe( rot );
rotated.add( builder.build() );
builder.setQuadOrientation( f2r.rotate( quad.getFace() ) );
BakedQuad q = builder.build();
rotated.add( q );
}
return rotated;
}
@ -116,75 +118,15 @@ public class CachingRotatingBakedModel implements IBakedModel
return quadCache.getUnchecked( new ImmutablePair<IBlockState, EnumFacing>( state, side ) );
}
public enum FacingToRotation
{
// DUNSWE
//@formatter:off
DOWN_DOWN ( new Vector3f( 0, 0, 0 ) ), //NOOP
DOWN_UP ( new Vector3f( 0, 0, 0 ) ), //NOOP
DOWN_NORTH ( new Vector3f( -90, 0, 0 ) ),
DOWN_SOUTH ( new Vector3f( -90, 0, 180 ) ),
DOWN_WEST ( new Vector3f( -90, 0, 90 ) ),
DOWN_EAST ( new Vector3f( -90, 0, -90 ) ),
UP_DOWN ( new Vector3f( 0, 0, 0 ) ), //NOOP
UP_UP ( new Vector3f( 0, 0, 0 ) ), //NOOP
UP_NORTH ( new Vector3f( 90, 0, 180 ) ),
UP_SOUTH ( new Vector3f( 90, 0, 0 ) ),
UP_WEST ( new Vector3f( 90, 0, 90 ) ),
UP_EAST ( new Vector3f( 90, 0, -90 ) ),
NORTH_DOWN ( new Vector3f( 0, 0, 180 ) ),
NORTH_UP ( new Vector3f( 0, 0, 0 ) ),
NORTH_NORTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
NORTH_SOUTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
NORTH_WEST ( new Vector3f( 0, 0, 90 ) ),
NORTH_EAST ( new Vector3f( 0, 0, -90 ) ),
SOUTH_DOWN ( new Vector3f( 0, 180, 180 ) ),
SOUTH_UP ( new Vector3f( 0, 180, 0 ) ),
SOUTH_NORTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
SOUTH_SOUTH ( new Vector3f( 0, 0, 0 ) ), //NOOP
SOUTH_WEST ( new Vector3f( 0, 180, -90 ) ),
SOUTH_EAST ( new Vector3f( 0, 180, 90 ) ),
WEST_DOWN ( new Vector3f( 0, 90, 180 ) ),
WEST_UP ( new Vector3f( 0, 90, 0 ) ),
WEST_NORTH ( new Vector3f( 0, 90, -90 ) ),
WEST_SOUTH ( new Vector3f( 0, 90, 90 ) ),
WEST_WEST ( new Vector3f( 0, 0, 0 ) ), //NOOP
WEST_EAST ( new Vector3f( 0, 0, 0 ) ), //NOOP
EAST_DOWN ( new Vector3f( 0, -90, 180 ) ),
EAST_UP ( new Vector3f( 0, -90, 0 ) ),
EAST_NORTH ( new Vector3f( 0, -90, 90 ) ),
EAST_SOUTH ( new Vector3f( 0, -90, -90 ) ),
EAST_WEST ( new Vector3f( 0, 0, 0 ) ), //NOOP
EAST_EAST ( new Vector3f( 0, 0, 0 ) ); //NOOP
//@formatter:on
private final Matrix4f mat;
private FacingToRotation( Vector3f rot )
{
this.mat = TRSRTransformation.toVecmath( new org.lwjgl.util.vector.Matrix4f().rotate( (float) Math.toRadians( rot.x ), new org.lwjgl.util.vector.Vector3f( 1, 0, 0 ) ).rotate( (float) Math.toRadians( rot.y ), new org.lwjgl.util.vector.Vector3f( 0, 1, 0 ) ).rotate( (float) Math.toRadians( rot.z ), new org.lwjgl.util.vector.Vector3f( 0, 0, 1 ) ) );
}
public Matrix4f getMat()
{
return new Matrix4f( this.mat );
}
public static FacingToRotation get( EnumFacing forward, EnumFacing up )
{
return values()[forward.ordinal() * 6 + up.ordinal()];
}
}
public class VertexRotator extends QuadGatheringTransformer
{
private final Matrix4f mat;
private final FacingToRotation f2r;
private final EnumFacing face;
public VertexRotator( Matrix4f mat )
public VertexRotator( FacingToRotation f2r, EnumFacing face )
{
this.mat = mat;
this.f2r = f2r;
this.face = face;
}
@Override
@ -213,6 +155,10 @@ public class CachingRotatingBakedModel implements IBakedModel
{
parent.put( e, transform( quadData[e][v] ) );
}
else if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
{
parent.put( e, transformNormal( quadData[e][v] ) );
}
else
{
parent.put( e, quadData[e][v] );
@ -230,7 +176,7 @@ public class CachingRotatingBakedModel implements IBakedModel
vec.x -= 0.5f;
vec.y -= 0.5f;
vec.z -= 0.5f;
mat.transform( vec );
f2r.getMat().transform( vec );
vec.x += 0.5f;
vec.y += 0.5f;
vec.z += 0.5f;
@ -240,7 +186,7 @@ public class CachingRotatingBakedModel implements IBakedModel
vecc.x -= 0.5f;
vecc.y -= 0.5f;
vecc.z -= 0.5f;
mat.transform( vecc );
f2r.getMat().transform( vecc );
vecc.x += 0.5f;
vecc.y += 0.5f;
vecc.z += 0.5f;
@ -251,6 +197,23 @@ public class CachingRotatingBakedModel implements IBakedModel
}
}
private float[] transformNormal( float[] fs )
{
switch( fs.length )
{
case 3:
Vec3i vec = f2r.rotate( face ).getDirectionVec();
return new float[] { vec.getX(), vec.getY(), vec.getZ() };
case 4:
Vector4f veccc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
Vec3i vecc = f2r.rotate( face ).getDirectionVec();
return new float[] { vecc.getX(), vecc.getY(), vecc.getZ(), veccc.w };
default:
return fs;
}
}
public void setQuadTint( int tint )
{

View file

@ -0,0 +1,87 @@
package appeng.client.render.tesr;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.ResourceLocation;
import appeng.block.storage.BlockSkyChest;
import appeng.block.storage.BlockSkyChest.SkyChestType;
import appeng.client.render.FacingToRotation;
import appeng.core.AppEng;
import appeng.tile.storage.TileSkyChest;
public class SkyChestTESR extends TileEntitySpecialRenderer<TileSkyChest>
{
private static final ResourceLocation TEXTURE_STONE = new ResourceLocation( AppEng.MOD_ID, "textures/models/skychest.png" );
private static final ResourceLocation TEXTURE_BLOCK = new ResourceLocation( AppEng.MOD_ID, "textures/models/skyblockchest.png" );
private final ModelChest simpleChest = new ModelChest();
public SkyChestTESR()
{
}
@Override
public void renderTileEntityAt( TileSkyChest te, double x, double y, double z, float partialTicks, int destroyStage )
{
GlStateManager.enableDepth();
GlStateManager.depthFunc( 515 );
GlStateManager.depthMask( true );
ModelChest modelchest;
modelchest = this.simpleChest;
if( destroyStage >= 0 )
{
this.bindTexture( DESTROY_STAGES[destroyStage] );
GlStateManager.matrixMode( 5890 );
GlStateManager.pushMatrix();
GlStateManager.scale( 4.0F, 4.0F, 1.0F );
GlStateManager.translate( 0.0625F, 0.0625F, 0.0625F );
GlStateManager.matrixMode( 5888 );
}
else
{
this.bindTexture( ( (BlockSkyChest) te.getBlockType() ).type == SkyChestType.STONE ? TEXTURE_STONE : TEXTURE_BLOCK );
}
GlStateManager.pushMatrix();
GlStateManager.enableRescaleNormal();
if( destroyStage < 0 )
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
}
GlStateManager.translate( (float) x, (float) y + 1.0F, (float) z + 1.0F );
GlStateManager.scale( 1.0F, -1.0F, -1.0F );
GlStateManager.translate( 0.5F, 0.5F, 0.5F );
FacingToRotation.get( te.getForward(), te.getUp() ).glRotateCurrentMat();
GlStateManager.translate( -0.5F, -0.5F, -0.5F );
float f = te.getPrevLidAngle() + ( te.getLidAngle() - te.getPrevLidAngle() ) * partialTicks;
f = 1.0F - f;
f = 1.0F - f * f * f;
modelchest.chestLid.rotateAngleX = -( f * ( (float) Math.PI / 2F ) );
modelchest.renderAll();
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
if( destroyStage >= 0 )
{
GlStateManager.matrixMode( 5890 );
GlStateManager.popMatrix();
GlStateManager.matrixMode( 5888 );
}
}
}

View file

@ -29,10 +29,13 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
@ -103,7 +106,16 @@ public final class AETileBlockFeatureHandler implements IFeatureHandler
if( side == Side.CLIENT )
{
TileEntitySpecialRenderer tesr = this.featured.getTESR();
ModelBakery.registerItemVariants( this.definition.maybeItem().get(), registryName );
if( tesr != null )
{
ClientRegistry.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), tesr );
if( this.featured.hasItemTESR() )
{
ForgeHooksClient.registerTESRItemStack( this.definition.maybeItem().get(), 0, this.featured.getTileEntityClass() );
}
}
}
}
}

View file

@ -43,6 +43,7 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -62,7 +63,7 @@ import appeng.util.Platform;
import appeng.util.SettingsFrom;
public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile, ICustomNameObject
public class AEBaseTile extends TileEntity implements ITickable, IOrientable, ICommonTile, ICustomNameObject
{
private static final ThreadLocal<WeakReference<AEBaseTile>> DROP_NO_ITEMS = new ThreadLocal<WeakReference<AEBaseTile>>();

View file

@ -33,7 +33,6 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
public class TileSkyChest extends AEBaseInvTile
@ -42,10 +41,11 @@ public class TileSkyChest extends AEBaseInvTile
private final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 };
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 * 4 );
// server
private int playerOpen;
private int numPlayersUsing;
// client..
private long lastEvent;
private float lidAngle;
private float prevLidAngle;
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileSkyChest( final ByteBuf data )
@ -73,6 +73,12 @@ public class TileSkyChest extends AEBaseInvTile
return true;
}
@Override
public boolean canRenderBreaking()
{
return true;
}
@Override
public IInventory getInternalInventory()
{
@ -82,39 +88,78 @@ public class TileSkyChest extends AEBaseInvTile
@Override
public void openInventory( final EntityPlayer player )
{
if( Platform.isClient() )
if( !player.isSpectator() )
{
return;
}
this.setPlayerOpen( this.getPlayerOpen() + 1 );
this.worldObj.addBlockEvent( this.pos, this.getBlockType(), 1, this.numPlayersUsing );
this.worldObj.notifyNeighborsOfStateChange( this.pos, this.getBlockType() );
this.worldObj.notifyNeighborsOfStateChange( this.pos.down(), this.getBlockType() );
this.setPlayerOpen( this.getPlayerOpen() + 1 );
if( this.getPlayerOpen() == 1 )
{
this.getWorld().playSound( player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.getWorld().rand.nextFloat() * 0.1F + 0.9F );
this.markForUpdate();
if( this.getPlayerOpen() == 1 )
{
this.getWorld().playSound( player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.getWorld().rand.nextFloat() * 0.1F + 0.9F );
this.markForUpdate();
}
}
}
@Override
public void closeInventory( final EntityPlayer player )
{
if( Platform.isClient() )
if( !player.isSpectator() )
{
return;
this.setPlayerOpen( this.getPlayerOpen() - 1 );
this.worldObj.addBlockEvent( this.pos, this.getBlockType(), 1, this.numPlayersUsing );
this.worldObj.notifyNeighborsOfStateChange( this.pos, this.getBlockType() );
this.worldObj.notifyNeighborsOfStateChange( this.pos.down(), this.getBlockType() );
if( this.getPlayerOpen() < 0 )
{
this.setPlayerOpen( 0 );
}
if( this.getPlayerOpen() == 0 )
{
this.getWorld().playSound( player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.getWorld().rand.nextFloat() * 0.1F + 0.9F );
this.markForUpdate();
}
}
}
this.setPlayerOpen( this.getPlayerOpen() - 1 );
@TileEvent( TileEventType.TICK )
public void tick()
{
int i = this.pos.getX();
int j = this.pos.getY();
int k = this.pos.getZ();
if( this.getPlayerOpen() < 0 )
this.prevLidAngle = this.lidAngle;
float f1 = 0.1F;
if( this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F )
{
this.setPlayerOpen( 0 );
}
float f2 = this.lidAngle;
if( this.getPlayerOpen() == 0 )
{
this.getWorld().playSound( player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.getWorld().rand.nextFloat() * 0.1F + 0.9F );
this.markForUpdate();
if( this.numPlayersUsing > 0 )
{
this.lidAngle += 0.1F;
}
else
{
this.lidAngle -= 0.1F;
}
if( this.lidAngle > 1.0F )
{
this.lidAngle = 1.0F;
}
float f3 = 0.5F;
if( this.lidAngle < 0.0F )
{
this.lidAngle = 0.0F;
}
}
}
@ -132,6 +177,7 @@ public class TileSkyChest extends AEBaseInvTile
public float getLidAngle()
{
// System.out.println( lidAngle );
return this.lidAngle;
}
@ -140,14 +186,24 @@ public class TileSkyChest extends AEBaseInvTile
this.lidAngle = lidAngle;
}
public float getPrevLidAngle()
{
return prevLidAngle;
}
public void setPrevLidAngle( float prevLidAngle )
{
this.prevLidAngle = prevLidAngle;
}
public int getPlayerOpen()
{
return this.playerOpen;
return this.numPlayersUsing;
}
private void setPlayerOpen( final int playerOpen )
{
this.playerOpen = playerOpen;
this.numPlayersUsing = playerOpen;
}
public long getLastEvent()

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"appliedenergistics2:items/ItemPaintBall"
}
}

View file

@ -0,0 +1,35 @@
{
"parent": "builtin/entity",
"display": {
"gui": {
"rotation": [ 30, 45, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.625, 0.625, 0.625 ]
},
"ground": {
"rotation": [ 0, 0, 0 ],
"translation": [ 0, 3, 0],
"scale":[ 0.25, 0.25, 0.25 ]
},
"head": {
"rotation": [ 0, 180, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 1, 1, 1]
},
"fixed": {
"rotation": [ 0, 180, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.5, 0.5, 0.5 ]
},
"thirdperson_righthand": {
"rotation": [ 75, 315, 0 ],
"translation": [ 0, 2.5, 0],
"scale": [ 0.375, 0.375, 0.375 ]
},
"firstperson_righthand": {
"rotation": [ 0, 315, 0 ],
"translation": [ 0, 0, 0],
"scale": [ 0.4, 0.4, 0.4 ]
}
}
}