Reimplemented cable and parts rendering.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
|
||||
/**
|
||||
* Used as the cache key for caching automatically rotated baked models.
|
||||
*/
|
||||
final class AutoRotatingCacheKey
|
||||
{
|
||||
private final IBlockState blockState;
|
||||
private final EnumFacing forward;
|
||||
private final EnumFacing up;
|
||||
private final EnumFacing side;
|
||||
|
||||
AutoRotatingCacheKey( IBlockState blockState, EnumFacing forward, EnumFacing up, EnumFacing side )
|
||||
{
|
||||
this.blockState = blockState;
|
||||
this.forward = forward;
|
||||
this.up = up;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public IBlockState getBlockState()
|
||||
{
|
||||
return blockState;
|
||||
}
|
||||
|
||||
public EnumFacing getForward()
|
||||
{
|
||||
return forward;
|
||||
}
|
||||
|
||||
public EnumFacing getUp()
|
||||
{
|
||||
return up;
|
||||
}
|
||||
|
||||
public EnumFacing getSide()
|
||||
{
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoRotatingCacheKey cacheKey = (AutoRotatingCacheKey) o;
|
||||
return blockState.equals( cacheKey.blockState ) && forward == cacheKey.forward && up == cacheKey.up && side == cacheKey.side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = blockState.hashCode();
|
||||
result = 31 * result + forward.hashCode();
|
||||
result = 31 * result + up.hashCode();
|
||||
result = 31 * result + ( side != null ? side.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
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.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.property.IExtendedBlockState;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
|
||||
|
||||
public class AutoRotatingModel implements IBakedModel
|
||||
{
|
||||
|
||||
private final IBakedModel parent;
|
||||
private final LoadingCache<AutoRotatingCacheKey, List<BakedQuad>> quadCache;
|
||||
|
||||
public AutoRotatingModel( IBakedModel parent )
|
||||
{
|
||||
this.parent = parent;
|
||||
// 6 (DUNSWE) * 6 (DUNSWE) * 7 (DUNSWE + null) = 252
|
||||
this.quadCache = CacheBuilder.newBuilder().maximumSize( 252 ).build( new CacheLoader<AutoRotatingCacheKey, List<BakedQuad>>()
|
||||
{
|
||||
@Override
|
||||
public List<BakedQuad> load( AutoRotatingCacheKey key ) throws Exception
|
||||
{
|
||||
return getRotatedModel( key.getBlockState(), key.getSide(), key.getForward(), key.getUp() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private List<BakedQuad> getRotatedModel( IBlockState state, EnumFacing side, EnumFacing forward, EnumFacing up )
|
||||
{
|
||||
FacingToRotation f2r = FacingToRotation.get( forward, up );
|
||||
List<BakedQuad> original = AutoRotatingModel.this.parent.getQuads( state, f2r.resultingRotate( side ), 0 );
|
||||
List<BakedQuad> rotated = new ArrayList<>( original.size() );
|
||||
for( BakedQuad quad : original )
|
||||
{
|
||||
VertexFormat format = quad.getFormat();
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder( format );
|
||||
VertexRotator rot = new VertexRotator( f2r, quad.getFace() );
|
||||
rot.setParent( builder );
|
||||
quad.pipe( rot );
|
||||
builder.setQuadOrientation( f2r.rotate( quad.getFace() ) );
|
||||
BakedQuad q = builder.build();
|
||||
rotated.add( q );
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return parent.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return parent.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return parent.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( !( state instanceof IExtendedBlockState ) )
|
||||
{
|
||||
return parent.getQuads( state, side, rand );
|
||||
}
|
||||
|
||||
IExtendedBlockState extState = (IExtendedBlockState) state;
|
||||
|
||||
EnumFacing forward = extState.getValue( AEBaseTileBlock.FORWARD );
|
||||
EnumFacing up = extState.getValue( AEBaseTileBlock.UP );
|
||||
|
||||
if( forward == null || up == null )
|
||||
{
|
||||
return parent.getQuads( state, side, rand );
|
||||
}
|
||||
|
||||
// The model has other properties than just forward/up, so it would cause our cache to inadvertendly also cache these
|
||||
// additional states, possibly leading to huge isseus if the other extended state properties do not implement equals/hashCode correctly
|
||||
if( extState.getUnlistedProperties().size() != 2 )
|
||||
{
|
||||
return getRotatedModel( extState, side, forward, up );
|
||||
}
|
||||
|
||||
AutoRotatingCacheKey key = new AutoRotatingCacheKey( extState.getClean(), forward, up, side );
|
||||
|
||||
return quadCache.getUnchecked( key );
|
||||
}
|
||||
|
||||
public static class VertexRotator extends QuadGatheringTransformer
|
||||
{
|
||||
private final FacingToRotation f2r;
|
||||
private final EnumFacing face;
|
||||
|
||||
public VertexRotator( FacingToRotation f2r, EnumFacing face )
|
||||
{
|
||||
this.f2r = f2r;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent( IVertexConsumer parent )
|
||||
{
|
||||
super.setParent( parent );
|
||||
if( Objects.equal( getVertexFormat(), parent.getVertexFormat() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
setVertexFormat( parent.getVertexFormat() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processQuad()
|
||||
{
|
||||
VertexFormat format = parent.getVertexFormat();
|
||||
int count = format.getElementCount();
|
||||
|
||||
for( int v = 0; v < 4; v++ )
|
||||
{
|
||||
for( int e = 0; e < count; e++ )
|
||||
{
|
||||
VertexFormatElement element = format.getElement( e );
|
||||
if( element.getUsage() == VertexFormatElement.EnumUsage.POSITION )
|
||||
{
|
||||
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] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transform( float[] fs )
|
||||
{
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
Vector3f vec = new Vector3f( fs[0], fs[1], fs[2] );
|
||||
vec.x -= 0.5f;
|
||||
vec.y -= 0.5f;
|
||||
vec.z -= 0.5f;
|
||||
f2r.getMat().transform( vec );
|
||||
vec.x += 0.5f;
|
||||
vec.y += 0.5f;
|
||||
vec.z += 0.5f;
|
||||
return new float[] {
|
||||
vec.x,
|
||||
vec.y,
|
||||
vec.z
|
||||
};
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
vecc.x -= 0.5f;
|
||||
vecc.y -= 0.5f;
|
||||
vecc.z -= 0.5f;
|
||||
f2r.getMat().transform( vecc );
|
||||
vecc.x += 0.5f;
|
||||
vecc.y += 0.5f;
|
||||
vecc.z += 0.5f;
|
||||
return new float[] {
|
||||
vecc.x,
|
||||
vecc.y,
|
||||
vecc.z,
|
||||
vecc.w
|
||||
};
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
parent.setQuadTint( tint );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadOrientation( EnumFacing orientation )
|
||||
{
|
||||
parent.setQuadOrientation( orientation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplyDiffuseLighting( boolean diffuse )
|
||||
{
|
||||
parent.setApplyDiffuseLighting( diffuse );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexture( TextureAtlasSprite texture )
|
||||
{
|
||||
parent.setTexture( texture );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
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.util.EnumFacing;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.client.render.model.pipeline.DoubleFacingQuadRotator;
|
||||
import appeng.client.render.model.pipeline.ParentQuads;
|
||||
import appeng.client.render.model.pipeline.TypeTransformer;
|
||||
|
||||
|
||||
public class CachingRotatingBakedModel implements IBakedModel
|
||||
{
|
||||
|
||||
private static final BakingPipeline<Void, BakedQuad> pipeline = new BakingPipeline<>( new ParentQuads(), TypeTransformer.quads2vecs, new DoubleFacingQuadRotator(), TypeTransformer.vecs2quads );
|
||||
private final IBakedModel parent;
|
||||
private final LoadingCache<Pair<IBlockState, EnumFacing>, List<BakedQuad>> quadCache;
|
||||
|
||||
public CachingRotatingBakedModel( IBakedModel parent )
|
||||
{
|
||||
this.parent = parent;
|
||||
// 6 (DUNSWE) * 6 (DUNSWE) * 7 (DUNSWE + null) = 252
|
||||
this.quadCache = CacheBuilder.newBuilder().maximumSize( 252 ).build( new CacheLoader<Pair<IBlockState, EnumFacing>, List<BakedQuad>>(){
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> load( Pair<IBlockState, EnumFacing> key ) throws Exception
|
||||
{
|
||||
return pipeline.pipe( null, parent, key.getLeft(), key.getRight(), 0 );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return parent.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return parent.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return parent.getOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( state == null )
|
||||
{
|
||||
return parent.getQuads( state, side, rand );
|
||||
}
|
||||
return quadCache.getUnchecked( new ImmutablePair<IBlockState, EnumFacing>( state, side ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
|
||||
|
||||
public class ModelCompass extends ModelBase
|
||||
{
|
||||
|
||||
private final ModelRenderer Ring1;
|
||||
private final ModelRenderer Ring2;
|
||||
private final ModelRenderer Ring3;
|
||||
private final ModelRenderer Ring4;
|
||||
private final ModelRenderer Middle;
|
||||
private final ModelRenderer Base;
|
||||
|
||||
private final ModelRenderer Pointer;
|
||||
|
||||
public ModelCompass()
|
||||
{
|
||||
this.textureWidth = 16;
|
||||
this.textureHeight = 8;
|
||||
|
||||
this.Ring1 = new ModelRenderer( this, 0, 0 );
|
||||
this.Ring1.addBox( 0F, 0F, 0F, 4, 1, 1 );
|
||||
this.Ring1.setRotationPoint( -2F, 22F, 2F );
|
||||
this.Ring1.setTextureSize( 16, 8 );
|
||||
this.Ring1.mirror = true;
|
||||
this.setRotation( this.Ring1, 0F, 0F, 0F );
|
||||
|
||||
this.Ring2 = new ModelRenderer( this, 0, 0 );
|
||||
this.Ring2.addBox( 0F, 0F, 0F, 1, 1, 4 );
|
||||
this.Ring2.setRotationPoint( -3F, 22F, -2F );
|
||||
this.Ring2.setTextureSize( 16, 8 );
|
||||
this.Ring2.mirror = true;
|
||||
this.setRotation( this.Ring2, 0F, 0F, 0F );
|
||||
|
||||
this.Ring3 = new ModelRenderer( this, 0, 0 );
|
||||
this.Ring3.addBox( 0F, 0F, 0F, 4, 1, 1 );
|
||||
this.Ring3.setRotationPoint( -2F, 22F, -3F );
|
||||
this.Ring3.setTextureSize( 16, 8 );
|
||||
this.Ring3.mirror = true;
|
||||
this.setRotation( this.Ring3, 0F, 0F, 0F );
|
||||
|
||||
this.Ring4 = new ModelRenderer( this, 0, 0 );
|
||||
this.Ring4.addBox( 0F, 0F, 0F, 1, 1, 4 );
|
||||
this.Ring4.setRotationPoint( 2F, 22F, -2F );
|
||||
this.Ring4.setTextureSize( 16, 8 );
|
||||
this.Ring4.mirror = true;
|
||||
this.setRotation( this.Ring4, 0F, 0F, 0F );
|
||||
|
||||
this.Middle = new ModelRenderer( this, 0, 0 );
|
||||
this.Middle.addBox( 0F, 0F, 0F, 1, 1, 1 );
|
||||
this.Middle.setRotationPoint( -0.5333334F, 22F, -0.5333334F );
|
||||
this.Middle.setTextureSize( 16, 8 );
|
||||
this.Middle.mirror = true;
|
||||
this.setRotation( this.Middle, 0F, 0F, 0F );
|
||||
|
||||
this.Pointer = new ModelRenderer( this, 0, 0 );
|
||||
this.Pointer.setTextureOffset( 0, 5 );
|
||||
this.Pointer.addBox( -0.5F, 0F, 0F, 1, 1, 2 );
|
||||
this.Pointer.setRotationPoint( 0.5F, 22.5F, 0.5F );
|
||||
this.Pointer.setTextureSize( 16, 8 );
|
||||
this.Pointer.mirror = true;
|
||||
this.Pointer.offsetZ = -0.034f;
|
||||
this.Pointer.offsetX = -0.034f;
|
||||
this.setRotation( this.Pointer, 0F, 0F, 0F );
|
||||
|
||||
this.Base = new ModelRenderer( this, 0, 0 );
|
||||
this.Base.addBox( 0F, 0F, 0F, 4, 1, 4 );
|
||||
this.Base.setRotationPoint( -2F, 23F, -2F );
|
||||
this.Base.setTextureSize( 16, 8 );
|
||||
this.Base.mirror = true;
|
||||
this.setRotation( this.Base, 0F, 0F, 0F );
|
||||
}
|
||||
|
||||
private void setRotation( final ModelRenderer model, final float x, final float y, final float z )
|
||||
{
|
||||
model.rotateAngleX = x;
|
||||
model.rotateAngleY = y;
|
||||
model.rotateAngleZ = z;
|
||||
}
|
||||
|
||||
public void renderAll( final float rad )
|
||||
{
|
||||
this.setRotation( this.Pointer, 0F, 0F, 0F );
|
||||
|
||||
this.Pointer.rotateAngleY = rad;
|
||||
|
||||
this.Base.render( 0.0625F );
|
||||
this.Middle.render( 0.0625F );
|
||||
|
||||
this.Pointer.render( 0.0625F );
|
||||
|
||||
this.Ring1.render( 0.0625F );
|
||||
this.Ring2.render( 0.0625F );
|
||||
this.Ring3.render( 0.0625F );
|
||||
this.Ring4.render( 0.0625F );
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
|
||||
package appeng.client.render.model;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
|
||||
|
||||
public enum ModelsCache implements IResourceManagerReloadListener
|
||||
{
|
||||
|
||||
INSTANCE;
|
||||
|
||||
public static final IModelState DEFAULTMODELSTATE = opt -> Optional.absent();
|
||||
public static final VertexFormat DEFAULTVERTEXFORMAT = DefaultVertexFormats.BLOCK;
|
||||
public static final Function<ResourceLocation, TextureAtlasSprite> DEFAULTTEXTUREGETTER = texture -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite( texture.toString() );
|
||||
|
||||
private final Map<ResourceLocation, IModel> cache = new HashMap<>();
|
||||
private final Map<ResourceLocation, IBakedModel> bakedCache = new HashMap<>();
|
||||
|
||||
public IModel getOrLoadModel( ResourceLocation location )
|
||||
{
|
||||
IModel model = cache.get( location );
|
||||
if( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel( location );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// TODO 1.10.2-R - log this in pretty way
|
||||
e.printStackTrace();
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
cache.put( location, model );
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public IBakedModel getModel( ResourceLocation key )
|
||||
{
|
||||
return bakedCache.get( key );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> textureGetter )
|
||||
{
|
||||
IBakedModel model = getModel( key );
|
||||
if( model == null )
|
||||
{
|
||||
model = getOrLoadModel( location ).bake( state, format, textureGetter );
|
||||
bakedCache.put( key, model );
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, IModelState state, VertexFormat format )
|
||||
{
|
||||
return getOrLoadModel( key, location, state, format, DEFAULTTEXTUREGETTER );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, IModelState state, Function<ResourceLocation, TextureAtlasSprite> textureGetter )
|
||||
{
|
||||
return getOrLoadModel( key, location, state, DEFAULTVERTEXFORMAT, textureGetter );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> textureGetter )
|
||||
{
|
||||
return getOrLoadModel( key, location, DEFAULTMODELSTATE, format, textureGetter );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, IModelState state )
|
||||
{
|
||||
return getOrLoadModel( key, location, state, DEFAULTVERTEXFORMAT, DEFAULTTEXTUREGETTER );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, VertexFormat format )
|
||||
{
|
||||
return getOrLoadModel( key, location, DEFAULTMODELSTATE, format, DEFAULTTEXTUREGETTER );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location, Function<ResourceLocation, TextureAtlasSprite> textureGetter )
|
||||
{
|
||||
return getOrLoadModel( key, location, DEFAULTMODELSTATE, DEFAULTVERTEXFORMAT, textureGetter );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadModel( ResourceLocation key, ResourceLocation location )
|
||||
{
|
||||
return getOrLoadModel( key, location, DEFAULTMODELSTATE, DEFAULTVERTEXFORMAT, DEFAULTTEXTUREGETTER );
|
||||
}
|
||||
|
||||
public IBakedModel getOrLoadBakedModel( ResourceLocation location )
|
||||
{
|
||||
return getOrLoadModel( location, location, DEFAULTMODELSTATE, DEFAULTVERTEXFORMAT, DEFAULTTEXTUREGETTER );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload( IResourceManager resourceManager )
|
||||
{
|
||||
cache.clear();
|
||||
bakedCache.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import com.google.common.collect.Lists;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
// TODO: Investigate use of CubeBuilder instead
|
||||
final class RenderHelper
|
||||
{
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.util.EnumFacing;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class BakingPipelineBakedModel extends BakingPipeline implements IBakedModel
|
||||
{
|
||||
|
||||
private final IBakedModel parent;
|
||||
public BakingPipelineBakedModel( IBakedModel parent, BakingPipelineElement<?, ?>... pipeline )
|
||||
{
|
||||
super( pipeline );
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
return pipe( new ArrayList(), parent, state, side, rand );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return parent.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return parent.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return parent.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return parent.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return parent.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return parent.getOverrides();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.client.render.FacingToRotation;
|
||||
|
||||
|
||||
public class DoubleFacingQuadRotator implements BakingPipelineElement<QuadVertexData, QuadVertexData>
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( state != null )
|
||||
{
|
||||
IExtendedBlockState extState = (IExtendedBlockState) state;
|
||||
|
||||
EnumFacing forward = extState.getValue( AEBaseTileBlock.FORWARD );
|
||||
if( forward == null )
|
||||
{
|
||||
forward = EnumFacing.NORTH;
|
||||
}
|
||||
EnumFacing up = extState.getValue( AEBaseTileBlock.UP );
|
||||
if( up == null )
|
||||
{
|
||||
up = EnumFacing.UP;
|
||||
}
|
||||
final FacingToRotation f2r = FacingToRotation.get( forward, up );
|
||||
List<QuadVertexData> rotated = new ArrayList<>();
|
||||
for( QuadVertexData data : elements )
|
||||
{
|
||||
data.setFace( f2r.rotate( data.getFace() ) );
|
||||
float[][][] qd = data.getData();
|
||||
for( int v = 0; v < 4; v++ )
|
||||
{
|
||||
for( int e = 0; e < data.getFormat().getElementCount(); e++ )
|
||||
{
|
||||
VertexFormatElement element = data.getFormat().getElement( e );
|
||||
if( element.getUsage() == VertexFormatElement.EnumUsage.POSITION )
|
||||
{
|
||||
qd[v][e] = transform( f2r, qd[v][e] );
|
||||
}
|
||||
else if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
|
||||
{
|
||||
qd[v][e] = transformNormal( f2r, qd[v][e] );
|
||||
}
|
||||
}
|
||||
}
|
||||
rotated.add( new QuadVertexData( data.getFormat(), qd, data.getTintIndex(), data.getFace(), data.getSprite(), data.shouldApplyDiffuseLighting() ) );
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
private float[] transform( FacingToRotation f2r, float[] fs )
|
||||
{
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
Vector3f vec = new Vector3f( fs[0], fs[1], fs[2] );
|
||||
vec.x -= 0.5f;
|
||||
vec.y -= 0.5f;
|
||||
vec.z -= 0.5f;
|
||||
f2r.getMat().transform( vec );
|
||||
vec.x += 0.5f;
|
||||
vec.y += 0.5f;
|
||||
vec.z += 0.5f;
|
||||
return new float[] { vec.x, vec.y, vec.z };
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
vecc.x -= 0.5f;
|
||||
vecc.y -= 0.5f;
|
||||
vecc.z -= 0.5f;
|
||||
f2r.getMat().transform( vecc );
|
||||
vecc.x += 0.5f;
|
||||
vecc.y += 0.5f;
|
||||
vecc.z += 0.5f;
|
||||
return new float[] { vecc.x, vecc.y, vecc.z, vecc.w };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transformNormal( FacingToRotation f2r, float[] fs )
|
||||
{
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
Vector3f vec = new Vector3f( fs[0], fs[1], fs[2] );
|
||||
f2r.getMat().transform( vec );
|
||||
return new float[] { vec.x, vec.y, vec.z };
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
f2r.getMat().transform( vecc );
|
||||
return new float[] { vecc.x, vecc.y, vecc.z, vecc.w };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
|
||||
public class FacingQuadRotator extends MatVecApplicator
|
||||
{
|
||||
|
||||
private EnumFacing override;
|
||||
|
||||
public FacingQuadRotator( EnumFacing override )
|
||||
{
|
||||
super( TRSRTransformation.getMatrix( override ) );
|
||||
this.override = override;
|
||||
}
|
||||
|
||||
public FacingQuadRotator()
|
||||
{
|
||||
this.override = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( override == null )
|
||||
{
|
||||
setMatrix( TRSRTransformation.getMatrix( side ) );
|
||||
}
|
||||
return super.pipe( elements, parent, state, side, rand );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class MatVecApplicator implements BakingPipelineElement<QuadVertexData, QuadVertexData>
|
||||
{
|
||||
|
||||
private Matrix4f matrix;
|
||||
private boolean forceTranslate;
|
||||
|
||||
public MatVecApplicator( Matrix4f matrix, boolean forceTranslate )
|
||||
{
|
||||
this.matrix = matrix;
|
||||
this.forceTranslate = forceTranslate;
|
||||
}
|
||||
|
||||
public MatVecApplicator( Matrix4f matrix )
|
||||
{
|
||||
this( matrix, false );
|
||||
}
|
||||
|
||||
public MatVecApplicator()
|
||||
{
|
||||
this( new Matrix4f() );
|
||||
}
|
||||
|
||||
public Matrix4f getMatrix()
|
||||
{
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public void setMatrix( Matrix4f matrix )
|
||||
{
|
||||
this.matrix = matrix;
|
||||
}
|
||||
|
||||
public boolean forceTranslate()
|
||||
{
|
||||
return forceTranslate;
|
||||
}
|
||||
|
||||
public void setForceTranslate( boolean forceTranslate )
|
||||
{
|
||||
this.forceTranslate = forceTranslate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
List<QuadVertexData> rotated = new ArrayList();
|
||||
for( QuadVertexData data : elements )
|
||||
{
|
||||
float[][][] qd = data.getData();
|
||||
data.setFace( side != null ? TRSRTransformation.rotate( matrix, side ) : side );
|
||||
for( int v = 0; v < 4; v++ )
|
||||
{
|
||||
for( int e = 0; e < data.getFormat().getElementCount(); e++ )
|
||||
{
|
||||
VertexFormatElement element = data.getFormat().getElement( e );
|
||||
if( element.getUsage() == VertexFormatElement.EnumUsage.POSITION )
|
||||
{
|
||||
qd[v][e] = transform( qd[v][e] );
|
||||
}
|
||||
else if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
|
||||
{
|
||||
qd[v][e] = transformNormal( qd[v][e] );
|
||||
}
|
||||
}
|
||||
}
|
||||
rotated.add( new QuadVertexData( data.getFormat(), qd, data.getTintIndex(), data.getFace(), data.getSprite(), data.shouldApplyDiffuseLighting() ) );
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
||||
private float[] transform( float[] fs )
|
||||
{
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
Vector4f vec = new Vector4f( fs[0], fs[1], fs[2], forceTranslate ? 1 : 0 );
|
||||
vec.x -= 0.5f;
|
||||
vec.y -= 0.5f;
|
||||
vec.z -= 0.5f;
|
||||
this.matrix.transform( vec );
|
||||
vec.x += 0.5f;
|
||||
vec.y += 0.5f;
|
||||
vec.z += 0.5f;
|
||||
return new float[] { vec.x, vec.y, vec.z };
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], forceTranslate ? 1 : fs[3] );
|
||||
vecc.x -= 0.5f;
|
||||
vecc.y -= 0.5f;
|
||||
vecc.z -= 0.5f;
|
||||
this.matrix.transform( vecc );
|
||||
vecc.x += 0.5f;
|
||||
vecc.y += 0.5f;
|
||||
vecc.z += 0.5f;
|
||||
return new float[] { vecc.x, vecc.y, vecc.z, vecc.w };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
private float[] transformNormal( float[] fs )
|
||||
{
|
||||
switch( fs.length )
|
||||
{
|
||||
case 3:
|
||||
Vector3f vec = new Vector3f( fs[0], fs[1], fs[2] );
|
||||
this.matrix.transform( vec );
|
||||
vec.normalize();
|
||||
return new float[] { vec.x, vec.y, vec.z };
|
||||
case 4:
|
||||
Vector4f vecc = new Vector4f( fs[0], fs[1], fs[2], fs[3] );
|
||||
this.matrix.transform( vecc );
|
||||
vecc.normalize();
|
||||
return new float[] { vecc.x, vecc.y, vecc.z, vecc.w };
|
||||
|
||||
default:
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class Merge<F, T> implements BakingPipelineElement<F, T>
|
||||
{
|
||||
|
||||
private final ImmutableList<BakingPipelineElement<?, ?>> pipeline;
|
||||
|
||||
public Merge( BakingPipelineElement<?, ?>... pipeline )
|
||||
{
|
||||
this.pipeline = ImmutableList.copyOf( pipeline );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List pipe( List elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
for( BakingPipelineElement<?, ?> element : pipeline )
|
||||
{
|
||||
elements.addAll( element.pipe( new ArrayList<>(), parent, state, side, rand ) );
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.util.EnumFacing;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
public class ParentQuads implements BakingPipelineElement<Void, BakedQuad>
|
||||
{
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> pipe( List<Void> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
return parent.getQuads( state, side, rand );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
|
||||
public final class QuadVertexData
|
||||
{
|
||||
|
||||
private static final Field unpackedData = ReflectionHelper.findField( UnpackedBakedQuad.class, "unpackedData" );
|
||||
|
||||
private static float[][][] unpackedData( UnpackedBakedQuad quad )
|
||||
{
|
||||
try
|
||||
{
|
||||
return (float[][][]) unpackedData.get( quad );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw Throwables.propagate( e );
|
||||
}
|
||||
}
|
||||
|
||||
private VertexFormat format;
|
||||
private float[][][] data;
|
||||
|
||||
private int tintIndex;
|
||||
private EnumFacing face;
|
||||
private TextureAtlasSprite sprite;
|
||||
protected boolean applyDiffuseLighting;
|
||||
|
||||
public QuadVertexData( VertexFormat format, float[][][] data, int tintIndex, EnumFacing face, TextureAtlasSprite sprite, boolean applyDiffuseLighting )
|
||||
{
|
||||
this.format = format;
|
||||
this.data = data;
|
||||
this.tintIndex = tintIndex;
|
||||
this.face = face;
|
||||
this.sprite = sprite;
|
||||
this.applyDiffuseLighting = applyDiffuseLighting;
|
||||
}
|
||||
|
||||
public QuadVertexData( UnpackedBakedQuad quad )
|
||||
{
|
||||
this( quad.getFormat(), unpackedData( quad ), quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting() );
|
||||
}
|
||||
|
||||
public UnpackedBakedQuad toQuad()
|
||||
{
|
||||
return new UnpackedBakedQuad( data, tintIndex, face, sprite, applyDiffuseLighting, format );
|
||||
}
|
||||
|
||||
public VertexFormat getFormat()
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat( VertexFormat format )
|
||||
{
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public float[][][] getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData( float[][][] data )
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getTintIndex()
|
||||
{
|
||||
return tintIndex;
|
||||
}
|
||||
|
||||
public void setTintIndex( int tintIndex )
|
||||
{
|
||||
this.tintIndex = tintIndex;
|
||||
}
|
||||
|
||||
public EnumFacing getFace()
|
||||
{
|
||||
return face;
|
||||
}
|
||||
|
||||
public void setFace( EnumFacing face )
|
||||
{
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getSprite()
|
||||
{
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public void setSprite( TextureAtlasSprite sprite )
|
||||
{
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public boolean shouldApplyDiffuseLighting()
|
||||
{
|
||||
return applyDiffuseLighting;
|
||||
}
|
||||
|
||||
public void setApplyDiffuseLighting( boolean applyDiffuseLighting )
|
||||
{
|
||||
this.applyDiffuseLighting = applyDiffuseLighting;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class StatePosRecolorator implements BakingPipelineElement<QuadVertexData, QuadVertexData>
|
||||
{
|
||||
|
||||
private IBlockAccess blockAccess;
|
||||
private BlockPos pos;
|
||||
private IBlockState state;
|
||||
|
||||
public StatePosRecolorator( IBlockAccess blockAccess, BlockPos pos, IBlockState state )
|
||||
{
|
||||
this.blockAccess = blockAccess;
|
||||
this.pos = pos;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public IBlockAccess getBlockAccess()
|
||||
{
|
||||
return blockAccess;
|
||||
}
|
||||
|
||||
public void setBlockAccess( IBlockAccess blockAccess )
|
||||
{
|
||||
this.blockAccess = blockAccess;
|
||||
}
|
||||
|
||||
public BlockPos getPos()
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void setPos( BlockPos pos )
|
||||
{
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public IBlockState getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState( IBlockState state )
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
for( QuadVertexData data : elements )
|
||||
{
|
||||
data.setTintIndex( Minecraft.getMinecraft().getBlockColors().colorMultiplier( this.state, blockAccess, this.pos, data.getTintIndex() ) );
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class TintIndexModifier implements BakingPipelineElement<QuadVertexData, QuadVertexData>
|
||||
{
|
||||
|
||||
private Function<Integer, Integer> tintTransformer;
|
||||
|
||||
public TintIndexModifier( Function<Integer, Integer> tintTransformer )
|
||||
{
|
||||
this.tintTransformer = tintTransformer;
|
||||
}
|
||||
|
||||
public Function<Integer, Integer> getTintTransformer()
|
||||
{
|
||||
return tintTransformer;
|
||||
}
|
||||
|
||||
public void setTintTransformer( Function<Integer, Integer> tintTransformer )
|
||||
{
|
||||
this.tintTransformer = tintTransformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
for( QuadVertexData quad : elements )
|
||||
{
|
||||
quad.setTintIndex( tintTransformer.apply( quad.getTintIndex() ) );
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
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.util.EnumFacing;
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
|
||||
|
||||
public class TypeTransformer
|
||||
{
|
||||
|
||||
public static final BakingPipelineElement<BakedQuad, QuadVertexData> quads2vecs = new BakingPipelineElement<BakedQuad, QuadVertexData>(){
|
||||
|
||||
@Override
|
||||
public List<QuadVertexData> pipe( List<BakedQuad> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
return Lists.transform( elements != null ? elements : new ArrayList<>(), ( quad ) -> {
|
||||
if( quad instanceof UnpackedBakedQuad )
|
||||
{
|
||||
return new QuadVertexData( (UnpackedBakedQuad) quad );
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] qdata = quad.getVertexData();
|
||||
float[][][] data = new float[4][quad.getFormat().getElementCount()][4];
|
||||
for( int v = 0; v < data.length; v++ )
|
||||
{
|
||||
float[][] vd = data[v];
|
||||
for( int e = 0; e < vd.length; e++ )
|
||||
{
|
||||
LightUtil.unpack( qdata, vd[e], quad.getFormat(), v, e );
|
||||
}
|
||||
}
|
||||
return new QuadVertexData( quad.getFormat(), data, quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public static final BakingPipelineElement<QuadVertexData, BakedQuad> vecs2quads = new BakingPipelineElement<QuadVertexData, BakedQuad>(){
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> pipe( List<QuadVertexData> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
return Lists.transform( elements != null ? elements : new ArrayList<>(), data -> data.toQuad() );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline.cable;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
import appeng.api.implementations.parts.IPartCable;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.client.render.model.pipeline.TintIndexModifier;
|
||||
import appeng.parts.CableBusContainer;
|
||||
|
||||
|
||||
public class CableAndConnections implements BakingPipelineElement<BakedQuad, BakedQuad>
|
||||
{
|
||||
|
||||
private final BakingPipeline rotatingPipeline;
|
||||
private final TintIndexModifier tintIndexModifier;
|
||||
private final BakingPipeline tintIndexFixPipeline;
|
||||
|
||||
public CableAndConnections( BakingPipeline rotatingPipeline, TintIndexModifier tintIndexModifier, BakingPipeline tintIndexFixPipeline )
|
||||
{
|
||||
this.rotatingPipeline = rotatingPipeline;
|
||||
this.tintIndexModifier = tintIndexModifier;
|
||||
this.tintIndexFixPipeline = tintIndexFixPipeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> pipe( List<BakedQuad> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( state != null )
|
||||
{
|
||||
CableBusContainer cableBus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
|
||||
IPart part = cableBus.getPart( AEPartLocation.INTERNAL );
|
||||
if( part instanceof IPartCable )
|
||||
{
|
||||
tintIndexModifier.setTintTransformer( tint -> ( AEPartLocation.INTERNAL.ordinal() << 2 ) | tint );
|
||||
elements.addAll( tintIndexFixPipeline.pipe( ( (IPartCable) part ).getOrBakeQuads( rotatingPipeline, state, side, rand ), parent, state, side, rand ) );
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline.cable;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.client.render.model.pipeline.TintIndexModifier;
|
||||
import appeng.parts.CableBusContainer;
|
||||
|
||||
|
||||
public class Facades implements BakingPipelineElement<BakedQuad, BakedQuad>
|
||||
{
|
||||
|
||||
private final BakingPipeline rotatingPipeline;
|
||||
private final TintIndexModifier tintIndexModifier;
|
||||
private final BakingPipeline tintIndexFixPipeline;
|
||||
|
||||
public Facades( BakingPipeline rotatingPipeline, TintIndexModifier tintIndexModifier, BakingPipeline tintIndexFixPipeline )
|
||||
{
|
||||
this.rotatingPipeline = rotatingPipeline;
|
||||
this.tintIndexModifier = tintIndexModifier;
|
||||
this.tintIndexFixPipeline = tintIndexFixPipeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> pipe( List<BakedQuad> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( state != null )
|
||||
{
|
||||
CableBusContainer cableBus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
|
||||
for( AEPartLocation facing : AEPartLocation.SIDE_LOCATIONS )
|
||||
{
|
||||
IFacadePart facade = cableBus.getFacadeContainer().getFacade( facing );
|
||||
if( facade != null )
|
||||
{
|
||||
tintIndexModifier.setTintTransformer( tint -> ( facing.ordinal() << 2 ) | tint );
|
||||
elements.addAll( tintIndexFixPipeline.pipe( facade.getOrBakeQuads( cableBus, rotatingPipeline, state, side, rand ), parent, state, side, rand ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
|
||||
package appeng.client.render.model.pipeline.cable;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.api.client.BakingPipelineElement;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.client.render.model.pipeline.TintIndexModifier;
|
||||
import appeng.parts.CableBusContainer;
|
||||
|
||||
|
||||
public class Parts implements BakingPipelineElement<BakedQuad, BakedQuad>
|
||||
{
|
||||
|
||||
private final BakingPipeline rotatingPipeline;
|
||||
private final TintIndexModifier tintIndexModifier;
|
||||
private final BakingPipeline tintIndexFixPipeline;
|
||||
|
||||
public Parts( BakingPipeline rotatingPipeline, TintIndexModifier tintIndexModifier, BakingPipeline tintIndexFixPipeline )
|
||||
{
|
||||
this.rotatingPipeline = rotatingPipeline;
|
||||
this.tintIndexModifier = tintIndexModifier;
|
||||
this.tintIndexFixPipeline = tintIndexFixPipeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> pipe( List<BakedQuad> elements, IBakedModel parent, IBlockState state, EnumFacing side, long rand )
|
||||
{
|
||||
if( state != null )
|
||||
{
|
||||
CableBusContainer cableBus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
|
||||
for( AEPartLocation facing : AEPartLocation.SIDE_LOCATIONS )
|
||||
{
|
||||
IPart part = cableBus.getPart( facing );
|
||||
if( part != null )
|
||||
{
|
||||
tintIndexModifier.setTintTransformer( tint -> ( facing.ordinal() << 2 ) | tint );
|
||||
elements.addAll( tintIndexFixPipeline.pipe( part.getOrBakeQuads( rotatingPipeline, state, side, rand ), parent, state, side, rand ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user