Implemented spatial pylon rendering.
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
package appeng.client.render.spatial;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.block.spatial.BlockSpatialPylon;
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import appeng.tile.spatial.TileSpatialPylon;
|
||||
|
||||
|
||||
/**
|
||||
* The baked model that will be used for rendering the spatial pylon.
|
||||
*/
|
||||
class SpatialPylonBakedModel implements IBakedModel
|
||||
{
|
||||
|
||||
private final Map<SpatialPylonTextureType, TextureAtlasSprite> textures;
|
||||
|
||||
private final VertexFormat format;
|
||||
|
||||
SpatialPylonBakedModel( VertexFormat format, Map<SpatialPylonTextureType, TextureAtlasSprite> textures )
|
||||
{
|
||||
this.textures = ImmutableMap.copyOf( textures );
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
|
||||
{
|
||||
int flags = getFlags( state );
|
||||
|
||||
CubeBuilder builder = new CubeBuilder( format );
|
||||
|
||||
if( flags != 0 )
|
||||
{
|
||||
EnumFacing ori = null;
|
||||
int displayAxis = flags & TileSpatialPylon.DISPLAY_Z;
|
||||
if( displayAxis == TileSpatialPylon.DISPLAY_X )
|
||||
{
|
||||
ori = EnumFacing.EAST;
|
||||
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MAX )
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.SOUTH, 1 );
|
||||
builder.setUvRotation( EnumFacing.NORTH, 1 );
|
||||
builder.setUvRotation( EnumFacing.UP, 2 );
|
||||
builder.setUvRotation( EnumFacing.DOWN, 1 );
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MIN )
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.SOUTH, 2 );
|
||||
builder.setUvRotation( EnumFacing.NORTH, 2 );
|
||||
builder.setUvRotation( EnumFacing.UP, 1 );
|
||||
builder.setUvRotation( EnumFacing.DOWN, 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.SOUTH, 1 );
|
||||
builder.setUvRotation( EnumFacing.NORTH, 1 );
|
||||
builder.setUvRotation( EnumFacing.UP, 1 );
|
||||
builder.setUvRotation( EnumFacing.DOWN, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
else if( displayAxis == TileSpatialPylon.DISPLAY_Y )
|
||||
{
|
||||
ori = EnumFacing.UP;
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MAX )
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.NORTH, 3 );
|
||||
builder.setUvRotation( EnumFacing.SOUTH, 3 );
|
||||
builder.setUvRotation( EnumFacing.EAST, 3 );
|
||||
builder.setUvRotation( EnumFacing.WEST, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
else if( displayAxis == TileSpatialPylon.DISPLAY_Z )
|
||||
{
|
||||
ori = EnumFacing.NORTH;
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MAX )
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.EAST, 2 );
|
||||
builder.setUvRotation( EnumFacing.WEST, 1 );
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MIN )
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.EAST, 1 );
|
||||
builder.setUvRotation( EnumFacing.WEST, 2 );
|
||||
builder.setUvRotation( EnumFacing.UP, 3 );
|
||||
builder.setUvRotation( EnumFacing.DOWN, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setUvRotation( EnumFacing.EAST, 1 );
|
||||
builder.setUvRotation( EnumFacing.WEST, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
builder.setTextures(
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.UP ) ),
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.DOWN ) ),
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.NORTH ) ),
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.SOUTH ) ),
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.EAST ) ),
|
||||
textures.get( getTextureTypeFromSideOutside( flags, ori, EnumFacing.WEST ) )
|
||||
);
|
||||
builder.addCube( 0, 0, 0, 16, 16, 16 );
|
||||
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_POWERED_ENABLED ) == TileSpatialPylon.DISPLAY_POWERED_ENABLED )
|
||||
{
|
||||
builder.setRenderFullBright( true );
|
||||
}
|
||||
|
||||
builder.setTextures(
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.UP ) ),
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.DOWN ) ),
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.NORTH ) ),
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.SOUTH ) ),
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.EAST ) ),
|
||||
textures.get( getTextureTypeFromSideInside( flags, ori, EnumFacing.WEST ) )
|
||||
);
|
||||
builder.addCube( 0, 0, 0, 16, 16, 16 );
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setTexture( textures.get( SpatialPylonTextureType.BASE ) );
|
||||
builder.addCube( 0, 0, 0, 16, 16, 16 );
|
||||
|
||||
builder.setTexture( textures.get( SpatialPylonTextureType.DIM ) );
|
||||
builder.addCube( 0, 0, 0, 16, 16, 16 );
|
||||
}
|
||||
|
||||
return builder.getOutput();
|
||||
}
|
||||
|
||||
private int getFlags( IBlockState state )
|
||||
{
|
||||
if( !( state instanceof IExtendedBlockState ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IExtendedBlockState extState = (IExtendedBlockState) state;
|
||||
|
||||
return extState.getValue( BlockSpatialPylon.STATE );
|
||||
}
|
||||
|
||||
private static SpatialPylonTextureType getTextureTypeFromSideOutside( int flags, EnumFacing ori, EnumFacing dir )
|
||||
{
|
||||
if( ori == dir || ori.getOpposite() == dir )
|
||||
{
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_MIDDLE )
|
||||
{
|
||||
return SpatialPylonTextureType.BASE_SPANNED;
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MIN )
|
||||
{
|
||||
return SpatialPylonTextureType.BASE_END;
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MAX )
|
||||
{
|
||||
return SpatialPylonTextureType.BASE_END;
|
||||
}
|
||||
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
private static SpatialPylonTextureType getTextureTypeFromSideInside( int flags, EnumFacing ori, EnumFacing dir )
|
||||
{
|
||||
final boolean good = ( flags & TileSpatialPylon.DISPLAY_ENABLED ) == TileSpatialPylon.DISPLAY_ENABLED;
|
||||
|
||||
if( ori == dir || ori.getOpposite() == dir )
|
||||
{
|
||||
return good ? SpatialPylonTextureType.DIM : SpatialPylonTextureType.RED;
|
||||
}
|
||||
|
||||
if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_MIDDLE )
|
||||
{
|
||||
return good ? SpatialPylonTextureType.DIM_SPANNED : SpatialPylonTextureType.RED_SPANNED;
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MIN )
|
||||
{
|
||||
return good ? SpatialPylonTextureType.DIM_END : SpatialPylonTextureType.RED_END;
|
||||
}
|
||||
else if( ( flags & TileSpatialPylon.DISPLAY_MIDDLE ) == TileSpatialPylon.DISPLAY_END_MAX )
|
||||
{
|
||||
return good ? SpatialPylonTextureType.DIM_END : SpatialPylonTextureType.RED_END;
|
||||
}
|
||||
|
||||
return SpatialPylonTextureType.BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package appeng.client.render.spatial;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
|
||||
class SpatialPylonModel implements IModel
|
||||
{
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return Arrays.stream( SpatialPylonTextureType.values() )
|
||||
.map( SpatialPylonModel::getTexturePath )
|
||||
.collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
Map<SpatialPylonTextureType, TextureAtlasSprite> textures = new EnumMap<>( SpatialPylonTextureType.class );
|
||||
|
||||
for( SpatialPylonTextureType type : SpatialPylonTextureType.values() )
|
||||
{
|
||||
ResourceLocation loc = getTexturePath( type );
|
||||
textures.put( type, bakedTextureGetter.apply( loc ) );
|
||||
}
|
||||
|
||||
return new SpatialPylonBakedModel( format, textures );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
private static ResourceLocation getTexturePath( SpatialPylonTextureType type )
|
||||
{
|
||||
return new ResourceLocation( AppEng.MOD_ID, "blocks/spatial_pylon/" + type.name().toLowerCase() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package appeng.client.render.spatial;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
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.core.AppEng;
|
||||
|
||||
|
||||
public class SpatialPylonRendering extends BlockRenderingCustomizer
|
||||
{
|
||||
|
||||
private static final ResourceLocation MODEL_ID = new ResourceLocation( AppEng.MOD_ID, "models/blocks/spatial_pylon/builtin" );
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
|
||||
{
|
||||
rendering.builtInModel( MODEL_ID.getResourcePath(), new SpatialPylonModel() );
|
||||
rendering.stateMapper( this::mapState );
|
||||
}
|
||||
|
||||
private Map<IBlockState, ModelResourceLocation> mapState( Block block )
|
||||
{
|
||||
return ImmutableMap.of(
|
||||
block.getDefaultState(), new ModelResourceLocation( MODEL_ID, "normal" )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package appeng.client.render.spatial;
|
||||
|
||||
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Models the rendering state of the spatial pylon, which is largely determined by the state of neighboring tiles.
|
||||
*/
|
||||
public class SpatialPylonStateProperty implements IUnlistedProperty<Integer>
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "spatial_state";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( Integer value )
|
||||
{
|
||||
int val = value;
|
||||
// The lower 6 bits are used
|
||||
return ( val & ~0x3F ) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Integer> getType()
|
||||
{
|
||||
return Integer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString( Integer value )
|
||||
{
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package appeng.client.render.spatial;
|
||||
|
||||
|
||||
enum SpatialPylonTextureType
|
||||
{
|
||||
BASE,
|
||||
BASE_END,
|
||||
BASE_SPANNED,
|
||||
DIM,
|
||||
DIM_END,
|
||||
DIM_SPANNED,
|
||||
RED,
|
||||
RED_END,
|
||||
RED_SPANNED
|
||||
}
|
||||
Reference in New Issue
Block a user