Reimplemented cable and parts rendering.

This commit is contained in:
Sebastian Hartte 2016-08-29 09:47:17 +02:00
parent 0b756708d4
commit 7e027da804
358 changed files with 5964 additions and 1901 deletions

View File

@ -0,0 +1,17 @@
package appeng.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks interfaces that can be used as injectable constructor arguments for an {@link AEPlugin}.
*/
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
public @interface AEInjectable
{
}

View File

@ -0,0 +1,20 @@
package appeng.api;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Use this annotation on a class in your Mod to have it instantiated during the initialization phase of Applied Energistics.
* AE expects your class to have a single constructor and can supply certain arguments to your constructor using dependency injection.
*/
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
@Documented
public @interface AEPlugin
{
}

View File

@ -33,7 +33,7 @@ import appeng.api.networking.IGridNode;
import appeng.api.parts.IPartHelper;
import appeng.api.storage.IStorageHelper;
@AEInjectable
public interface IAppEngApi
{
/**

View File

@ -24,8 +24,10 @@
package appeng.api.features;
import appeng.api.AEInjectable;
import appeng.api.movable.IMovableRegistry;
import appeng.api.networking.IGridCacheRegistry;
import appeng.api.parts.IPartModels;
import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IExternalStorageRegistry;
@ -36,6 +38,7 @@ import appeng.api.storage.IExternalStorageRegistry;
* @version rv2
* @since rv0
*/
@AEInjectable
public interface IRegistryContainer
{
@ -109,4 +112,9 @@ public interface IRegistryContainer
* get access to the world-gen api.
*/
IWorldGen worldgen();
/**
* Register your IPart models before using them.
*/
IPartModels partModels();
}

View File

@ -28,7 +28,6 @@ public enum BusSupport
{
CABLE,
DENSE_CABLE,
NO_PARTS
DENSE_CABLE
}

View File

@ -24,19 +24,11 @@
package appeng.api.parts;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.client.BakingPipeline;
import appeng.api.util.AEPartLocation;
@ -80,7 +72,4 @@ public interface IFacadePart
void setThinFacades( boolean useThinFacades );
boolean isTransparent();
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( IPartHost host, BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline, IBlockState state, EnumFacing side, long rand );
}

View File

@ -25,30 +25,29 @@ package appeng.api.parts;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.client.BakingPipeline;
import appeng.api.networking.IGridNode;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
@ -69,6 +68,15 @@ public interface IPart extends IBoxProvider, ICustomCableConnection
*/
ItemStack getItemStack( PartItemStack type );
/**
* Render dynamic portions of this part, as part of the cable bus TESR. This part has to return true for {@link #requireDynamicRender()} in order for
* this method to be called.
*/
@SideOnly( Side.CLIENT )
default void renderDynamic( double x, double y, double z, float partialTicks, int destroyStage )
{
}
/**
* return true only if your part require dynamic rendering, must be consistent.
*
@ -255,7 +263,27 @@ public interface IPart extends IBoxProvider, ICustomCableConnection
*/
boolean canBePlacedOn( BusSupport what );
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline, IBlockState state, EnumFacing side, long rand );
/**
* This method is used when a chunk is rebuilt to determine how this part should be rendered. The returned models should represent the
* part oriented north. They will be automatically rotated to match the part's actual orientation. Tint indices 1-4 can be used in the
* models to access the parts color.
*
* <dl>
* <dt>Tint Index 1</dt>
* <dd>The {@link AEColor#blackVariant dark variant color} of the cable that this part is attached to.</dd>
* <dt>Tint Index 2</dt>
* <dd>The {@link AEColor#mediumVariant color} of the cable that this part is attached to.</dd>
* <dt>Tint Index 3</dt>
* <dd>The {@link AEColor#whiteVariant bright variant color} of the cable that this part is attached to.</dd>
* <dt>Tint Index 4</dt>
* <dd>A color variant that is between the cable's {@link AEColor#mediumVariant color} and its {@link AEColor#whiteVariant bright variant}.</dd>
* </dl>
*
* <b>Important:</b> All models must have been registered via the {@link IPartModels} API before use.
*/
default List<ResourceLocation> getStaticModels()
{
return Collections.emptyList();
}
}

View File

@ -0,0 +1,35 @@
package appeng.api.parts;
import java.util.Arrays;
import java.util.Collection;
import net.minecraft.util.ResourceLocation;
import appeng.api.AEInjectable;
/**
* Allows registration of part models that can then be used in {@link IPart#getStaticModels()}.
*/
@AEInjectable
public interface IPartModels
{
/**
* Allows registration of part models that can then be used in {@link IPart#getStaticModels()}.
*
* Models can be registered multiple times without causing issues.
*
* This method must be called during the pre-init phase (as part of your plugin's constructor).
*/
void registerModels( Collection<ResourceLocation> partModels );
/**
* Convenience overload of {@link #registerModels(Collection)}
*/
default void registerModels( ResourceLocation... partModels )
{
registerModels( Arrays.asList( partModels ) );
}
}

View File

@ -26,49 +26,61 @@ package appeng.api.util;
import net.minecraft.util.ResourceLocation;
import appeng.client.render.cablebus.CableCoreType;
import appeng.core.AppEng;
public enum AECableType
{
/**
* No Cable present.
*/
NONE( null, 0 ),
NONE( null, 0, null, null ),
/**
* Connections to this block should render as glass.
*/
GLASS( "glass", 0 ),
GLASS( "glass", 0, CableCoreType.GLASS, "parts/cable/glass/" ),
/**
* Connections to this block should render as covered.
*/
COVERED( "covered", 0 ),
COVERED( "covered", 0, CableCoreType.COVERED, "parts/cable/covered/" ),
/**
* Connections to this block should render as smart.
*/
SMART( "smart", 8 ),
SMART( "smart", 8, CableCoreType.COVERED, "parts/cable/smart/" ),
/**
* Dense Cable, represents a tier 2 block that can carry 32 channels.
*/
DENSE( "dense", 32 );
DENSE( "dense", 32, CableCoreType.DENSE, "parts/cable/dense/" );
public static final AECableType[] VALIDCABLES = { GLASS, COVERED, SMART, DENSE };
public static final AECableType[] VALIDCABLES = {
GLASS,
COVERED,
SMART,
DENSE
};
private final CableCoreType coreType;
private final String type;
private final int displayedChannels;
private final ResourceLocation model;
private final ResourceLocation connectionModel;
private final ResourceLocation straightModel;
private final String textureFolder;
private AECableType( String type, int displayedChannels )
private AECableType( String type, int displayedChannels, CableCoreType coreType, String textureFolder )
{
this.type = type;
this.displayedChannels = displayedChannels;
this.model = new ResourceLocation( "appliedenergistics2", "part/cable/" + type + "/center" );
this.connectionModel = new ResourceLocation( "appliedenergistics2", "part/cable/" + type + "/connection" );
this.straightModel = new ResourceLocation( "appliedenergistics2", "part/cable/" + type + "/straight" );
this.coreType = coreType;
this.textureFolder = textureFolder;
}
public int displayedChannels()
@ -91,4 +103,21 @@ public enum AECableType
return straightModel;
}
/**
* @return The type of core that should be rendered when this cable isn't straight and needs to have a core to attach connections to. Is null for the NULL
* cable.
*/
public CableCoreType getCoreType()
{
return coreType;
}
public ResourceLocation getConnectionTexture( AEColor color )
{
if ( textureFolder == null ) {
throw new IllegalStateException( "Cable type " + name() + " does not support connections." );
}
return new ResourceLocation( AppEng.MOD_ID, textureFolder + color.name().toLowerCase() );
}
}

View File

@ -27,6 +27,7 @@ package appeng.api.util;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.text.translation.I18n;
@ -75,6 +76,27 @@ public enum AEColor
public static final List<AEColor> VALID_COLORS = Arrays.asList( White, Orange, Magenta, LightBlue, Yellow, Lime, Pink, Gray, LightGray, Cyan, Purple, Blue, Brown, Green, Red, Black );
/**
* The {@link BakedQuad#getTintIndex() tint index} that can normally be used to get the {@link #blackVariant dark variant} of the apprioriate AE color.
*/
public static final int TINTINDEX_DARK = 1;
/**
* The {@link BakedQuad#getTintIndex() tint index} that can normally be used to get the {@link #mediumVariant medium variant} of the apprioriate AE color.
*/
public static final int TINTINDEX_MEDIUM = 2;
/**
* The {@link BakedQuad#getTintIndex() tint index} that can normally be used to get the {@link #whiteVariant bright variant} of the apprioriate AE color.
*/
public static final int TINTINDEX_BRIGHT = 3;
/**
* The {@link BakedQuad#getTintIndex() tint index} that can normally be used to get a color between the {@link #mediumVariant medium}
* and {@link #whiteVariant bright variant} of the apprioriate AE color.
*/
public static final int TINTINDEX_MEDIUM_BRIGHT = 4;
/**
* Unlocalized name for color.
*/
@ -109,6 +131,35 @@ public enum AEColor
this.dye = dye;
}
/**
* Will return a variant of this color based on the given tint index.
*
* @param tintIndex A tint index as it can be used for {@link BakedQuad#getTintIndex()}.
* @return The appropriate color variant, or -1.
*/
public int getVariantByTintIndex( int tintIndex )
{
switch( tintIndex )
{
// Please note that tintindex 0 is hardcoded for the block breaking particles. Returning anything other than -1 for tintindex=0 here
// will cause issues with those particles
case 0:
return -1;
case TINTINDEX_DARK:
return blackVariant;
case TINTINDEX_MEDIUM:
return mediumVariant;
case TINTINDEX_BRIGHT:
return whiteVariant;
case TINTINDEX_MEDIUM_BRIGHT:
final int light = whiteVariant;
final int dark = mediumVariant;
return ( ( ( ( ( light >> 16 ) & 0xff ) + ( ( dark >> 16 ) & 0xff ) ) / 2 ) << 16 ) | ( ( ( ( ( light >> 8 ) & 0xff ) + ( ( dark >> 8 ) & 0xff ) ) / 2 ) << 8 ) | ( ( ( ( light ) & 0xff ) + ( ( dark ) & 0xff ) ) / 2 );
default:
return -1;
}
}
/**
* Logic to see which colors match each other.. special handle for Transparent
*/

View File

@ -28,7 +28,11 @@ import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleDigging;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -57,6 +61,8 @@ import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEColor;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.cablebus.CableBusBakedModel;
import appeng.client.render.cablebus.CableBusRenderState;
import appeng.core.AEConfig;
import appeng.core.Api;
import appeng.core.features.AEFeature;
@ -68,15 +74,21 @@ import appeng.parts.ICableBusContainer;
import appeng.parts.NullCableBusContainer;
import appeng.tile.AEBaseTile;
import appeng.tile.networking.TileCableBus;
import appeng.tile.networking.TileCableBusTESR;
import appeng.util.Platform;
public class BlockCableBus extends AEBaseTileBlock
{
public static final CableBusRenderStateProperty RENDER_STATE_PROPERTY = new CableBusRenderStateProperty();
private static final ICableBusContainer NULL_CABLE_BUS = new NullCableBusContainer();
private static Class<? extends AEBaseTile> noTesrTile;
private static Class<? extends AEBaseTile> tesrTile;
public BlockCableBus()
{
super( AEGlassMaterial.INSTANCE );
@ -89,8 +101,6 @@ public class BlockCableBus extends AEBaseTileBlock
this.setTileEntity( TileCableBus.class );
}
public static final CableBusContainerUnlistedProperty cableBus = new CableBusContainerUnlistedProperty();
@Override
public boolean isFullCube( IBlockState state )
{
@ -100,14 +110,15 @@ public class BlockCableBus extends AEBaseTileBlock
@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState( this, new IProperty[0], new IUnlistedProperty[] { FORWARD, UP, cableBus } );
return new ExtendedBlockState( this, new IProperty[0], new IUnlistedProperty[] { RENDER_STATE_PROPERTY } );
}
@Override
public IBlockState getExtendedState( IBlockState state, IBlockAccess world, BlockPos pos )
{
return ( (IExtendedBlockState) super.getExtendedState( state, world, pos ) )
.withProperty( cableBus, ( (TileCableBus) world.getTileEntity( pos ) ).getCableBus() );
CableBusRenderState renderState = cb( world, pos ).getRenderState();
return ( (IExtendedBlockState) state )
.withProperty( RENDER_STATE_PROPERTY, renderState );
}
@Override
@ -274,24 +285,40 @@ public class BlockCableBus extends AEBaseTileBlock
@Override
public boolean addDestroyEffects( final World world, final BlockPos pos, final ParticleManager effectRenderer )
{
final Object object = this.cb( world, pos );
if( object instanceof IPartHost )
{
final IPartHost host = (IPartHost) object;
ICableBusContainer cb = this.cb( world, pos );
// TODO DESTROY EFFECTS
/*
* for( AEPartLocation side : AEPartLocation.values() ) { IPart p =
* host.getPart( side ); TextureAtlasSprite ico = this.getIcon( p );
* if( ico == null ) { continue; } byte b0 = 3; for( int i1 = 0; i1
* < b0; ++i1 ) { for( int j1 = 0; j1 < b0; ++j1 ) { for( int k1 =
* 0; k1 < b0; ++k1 ) { double d0 = x + ( i1 + 0.5D ) / b0; double
* d1 = y + ( j1 + 0.5D ) / b0; double d2 = z + ( k1 + 0.5D ) / b0;
* EntityDiggingFX fx = ( new EntityDiggingFX( world, d0, d1, d2, d0
* - x - 0.5D, d1 - y - 0.5D, d2 - z - 0.5D, this, meta )
* ).applyColourMultiplier( x, y, z ); fx.setParticleIcon( ico );
* effectRenderer.addEffect( fx ); } } } }
*/
// Our built-in model has the actual baked sprites we need
IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState( getDefaultState() );
// We cannot add the effect if we dont have the model
if( !( model instanceof CableBusBakedModel ) )
{
return true;
}
CableBusBakedModel cableBusModel = (CableBusBakedModel) model;
CableBusRenderState renderState = cb.getRenderState();
for( TextureAtlasSprite texture : cableBusModel.getParticleTextures( renderState ) )
{
// Shamelessly inspired by ParticleManager.addBlockDestroyEffects
for( int j = 0; j < 4; ++j )
{
for( int k = 0; k < 4; ++k )
{
for( int l = 0; l < 4; ++l )
{
double d0 = (double) pos.getX() + ( (double) j + 0.5D ) / 4.0D;
double d1 = (double) pos.getY() + ( (double) k + 0.5D ) / 4.0D;
double d2 = (double) pos.getZ() + ( (double) l + 0.5D ) / 4.0D;
ParticleDigging particle = new DestroyFX( world, d0, d1, d2, d0 - (double) pos.getX() - 0.5D, d1 - (double) pos.getY() - 0.5D, d2 - (double) pos.getZ() - 0.5D, getDefaultState() )
.setBlockPos( pos );
particle.setParticleTexture( texture );
effectRenderer.addEffect( particle );
}
}
}
}
return true;
@ -356,9 +383,14 @@ public class BlockCableBus extends AEBaseTileBlock
public void setupTile()
{
noTesrTile = Api.INSTANCE.partHelper().getCombinedInstance( TileCableBus.class.getName() );
noTesrTile = Api.INSTANCE.partHelper().getCombinedInstance( TileCableBus.class );
this.setTileEntity( noTesrTile );
GameRegistry.registerTileEntity( noTesrTile, "BlockCableBus" );
if( Platform.isClient() )
{
tesrTile = Api.INSTANCE.partHelper().getCombinedInstance( TileCableBusTESR.class );
GameRegistry.registerTileEntity( tesrTile, "ClientOnly_TESR_CableBus" );
}
}
public static Class<? extends AEBaseTile> getNoTesrTile()
@ -366,4 +398,17 @@ public class BlockCableBus extends AEBaseTileBlock
return noTesrTile;
}
public static Class<? extends AEBaseTile> getTesrTile()
{
return tesrTile;
}
// Helper to get access to the protected constructor
private static class DestroyFX extends ParticleDigging
{
DestroyFX( World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, IBlockState state )
{
super( worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, state );
}
}
}

View File

@ -10,10 +10,12 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.parts.CableBusContainer;
import appeng.client.render.cablebus.CableBusRenderState;
/**
* Exposes the cable bus color as tint indices 0 (dark variant), 1 (medium variant) and 2 (bright variant).
*/
@SideOnly( Side.CLIENT )
public class CableBusColor implements IBlockColor
{
@ -22,32 +24,18 @@ public class CableBusColor implements IBlockColor
public int colorMultiplier( IBlockState state, IBlockAccess worldIn, BlockPos pos, int color )
{
boolean active = true;
AEColor busColor = AEColor.Transparent;
if( state instanceof IExtendedBlockState )
{
AEPartLocation side = AEPartLocation.fromOrdinal( ( color >> 2 ) & 7 );
CableBusContainer bus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
if( bus != null )
CableBusRenderState renderState = ( (IExtendedBlockState) state ).getValue( BlockCableBus.RENDER_STATE_PROPERTY );
if( renderState != null )
{
active = bus.getGridNode( side ) != null && bus.getGridNode( side ).isActive();
busColor = bus.getColor();
busColor = renderState.getCableColor();
}
}
switch( color & 3 )
{
case 0:
return active ? 0xffffff : 0;
case 1:
return busColor.blackVariant;
case 2:
return busColor.mediumVariant;
case 3:
return busColor.whiteVariant;
default:
return color;
}
return busColor.getVariantByTintIndex( color );
}
}

View File

@ -0,0 +1,37 @@
package appeng.block.networking;
import net.minecraftforge.common.property.IUnlistedProperty;
import appeng.client.render.cablebus.CableBusRenderState;
/**
* An unlisted property for the cable bus block's render state.
*/
public class CableBusRenderStateProperty implements IUnlistedProperty<CableBusRenderState>
{
@Override
public String getName()
{
return "cable_bus_render_state";
}
@Override
public boolean isValid( CableBusRenderState value )
{
return value != null;
}
@Override
public Class<CableBusRenderState> getType()
{
return CableBusRenderState.class;
}
@Override
public String valueToString( CableBusRenderState value )
{
return value.toString();
}
}

View File

@ -1,24 +1,14 @@
package appeng.block.networking;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.client.BakingPipeline;
import appeng.bootstrap.BlockRenderingCustomizer;
import appeng.bootstrap.IBlockRendering;
import appeng.bootstrap.IItemRendering;
import appeng.client.render.model.pipeline.BakingPipelineBakedModel;
import appeng.client.render.model.pipeline.FacingQuadRotator;
import appeng.client.render.model.pipeline.Merge;
import appeng.client.render.model.pipeline.TintIndexModifier;
import appeng.client.render.model.pipeline.TypeTransformer;
import appeng.client.render.model.pipeline.cable.CableAndConnections;
import appeng.client.render.model.pipeline.cable.Facades;
import appeng.client.render.model.pipeline.cable.Parts;
import appeng.client.render.cablebus.CableBusModel;
import appeng.core.features.registries.PartModels;
/**
@ -26,27 +16,19 @@ import appeng.client.render.model.pipeline.cable.Parts;
*/
public class CableBusRendering extends BlockRenderingCustomizer
{
private final PartModels partModels;
private final BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline = new BakingPipeline<>( TypeTransformer.quads2vecs, new FacingQuadRotator(), TypeTransformer.vecs2quads );
private final TintIndexModifier tintIndexModifier = new TintIndexModifier( tint -> tint );
private final BakingPipeline<BakedQuad, BakedQuad> tintIndexFixPipeline = new BakingPipeline<>( TypeTransformer.quads2vecs, tintIndexModifier, TypeTransformer.vecs2quads );
public CableBusRendering( PartModels partModels )
{
this.partModels = partModels;
}
@Override
@SideOnly( Side.CLIENT )
public void customize( IBlockRendering rendering, IItemRendering itemRendering )
{
rendering.modelCustomizer( this::customizeModel );
rendering.builtInModel( "models/block/builtin/cable_bus", new CableBusModel( partModels ) );
rendering.blockColor( new CableBusColor() );
}
private IBakedModel customizeModel( ResourceLocation location, IBakedModel model )
{
return new BakingPipelineBakedModel( model,
new Merge<>(
new CableAndConnections( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ),
new Facades( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ),
new Parts( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline )
)
);
rendering.modelCustomizer( ( loc, model ) -> model );
}
}

View File

@ -19,7 +19,7 @@ import appeng.block.AEBaseTileBlock;
import appeng.bootstrap.components.BlockColorComponent;
import appeng.bootstrap.components.StateMapperComponent;
import appeng.bootstrap.components.TesrComponent;
import appeng.client.render.model.CachingRotatingBakedModel;
import appeng.client.render.model.AutoRotatingModel;
class BlockRendering implements IBlockRendering
@ -96,7 +96,7 @@ class BlockRendering implements IBlockRendering
else if ( block instanceof AEBaseTileBlock )
{
// This is a default rotating model if the base-block uses an AE tile entity which exposes UP/FRONT as extended props
factory.modelOverrideComponent.addOverride( block.getRegistryName().getResourcePath(), ( l, m ) -> new CachingRotatingBakedModel( m ) );
factory.modelOverrideComponent.addOverride( block.getRegistryName().getResourcePath(), ( l, m ) -> new AutoRotatingModel( m ) );
}
builtInModels.forEach( factory::addBuiltInModel );

View File

@ -24,33 +24,28 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.google.common.collect.ImmutableMap;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import appeng.api.parts.CableRenderMode;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.block.AEBaseBlock;
import appeng.client.render.effects.AssemblerFX;
@ -59,12 +54,10 @@ import appeng.client.render.effects.EnergyFx;
import appeng.client.render.effects.LightningArcFX;
import appeng.client.render.effects.LightningFX;
import appeng.client.render.effects.VibrantFX;
import appeng.client.render.model.ModelsCache;
import appeng.client.render.model.UVLModelLoader;
import appeng.client.render.textures.ParticleTextures;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.CommonHelper;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketAssemblerAnimation;
@ -76,8 +69,6 @@ import appeng.entity.RenderTinyTNTPrimed;
import appeng.helpers.IMouseWheelItem;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
import appeng.items.parts.PartType;
import appeng.parts.AEBasePart;
import appeng.server.ServerHelper;
import appeng.transformer.MissingCoreMod;
import appeng.util.Platform;
@ -91,7 +82,6 @@ public class ClientHelper extends ServerHelper
{
MinecraftForge.EVENT_BUS.register( this );
ModelLoaderRegistry.registerLoader( UVLModelLoader.INSTANCE );
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() ).registerReloadListener( ModelsCache.INSTANCE );
}
@Override
@ -204,26 +194,26 @@ public class ClientHelper extends ServerHelper
}
@Override
public void doRenderItem( final ItemStack itemstack, final World w )
public void doRenderItem( final ItemStack itemstack )
{
if( itemstack != null )
{
final EntityItem entityitem = new EntityItem( w, 0.0D, 0.0D, 0.0D, itemstack );
entityitem.getEntityItem().stackSize = 1;
// set all this stuff and then do shit? meh?
entityitem.hoverStart = 0;
entityitem.setNoDespawn();
entityitem.rotationYaw = 0;
GlStateManager.pushMatrix();
GL11.glPushMatrix();
GL11.glTranslatef( 0, -0.04F, 0 );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
// GL11.glDisable( GL11.GL_CULL_FACE );
// The Z-scaling by 0.0001 causes the model to be visually "flattened"
// This cannot replace a proper projection, but it's cheap and gives the desired
// effect at least from head-on
final float scale = 0.8f;
GlStateManager.scale( scale / 32.0f, scale / 32.0f, 0.0001f );
// Position the item icon at the top middle of the panel
GlStateManager.translate( -8, -11, 0 );
// TODO RENDER ITEM FOR STORAGE MONITOR!
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
renderItem.renderItemAndEffectIntoGUI(itemstack, 0, 0);
GlStateManager.popMatrix();
GL11.glPopMatrix();
}
}
@ -398,47 +388,5 @@ public class ClientHelper extends ServerHelper
public void onTextureStitch( final TextureStitchEvent.Pre event )
{
ParticleTextures.registerSprite( event );
for( AECableType type : AECableType.VALIDCABLES )
{
for( IModel model : new IModel[] { ModelsCache.INSTANCE.getOrLoadModel( type.getModel() ), ModelsCache.INSTANCE.getOrLoadModel( type.getConnectionModel() ), ModelsCache.INSTANCE.getOrLoadModel( type.getStraightModel() ) } )
{
for( ResourceLocation location : model.getTextures() )
{
for( AEColor color : AEColor.values() )
{
if( type.displayedChannels() > 0 )
{
for( int i = 0; i <= type.displayedChannels(); i++ )
{
event.getMap().registerSprite( AEBasePart.replaceProperties( location, ImmutableMap.of( "color", color.name(), "channels", String.valueOf( i ) ) ) );
}
}
else
{
event.getMap().registerSprite( AEBasePart.replaceProperties( location, ImmutableMap.of( "color", color.name() ) ) );
}
}
}
}
}
for( PartType part : PartType.values() )
{
if( !part.isCable() )
{
IModel model = ModelsCache.INSTANCE.getOrLoadModel( part.getModel() );
for( ResourceLocation location : model.getTextures() )
{
for( AEColor color : AEColor.values() )
{
event.getMap().registerSprite( AEBasePart.replaceProperties( location, ImmutableMap.of( "color", color.name() ) ) );
}
}
}
}
for( ResourceLocation location : ModelsCache.INSTANCE.getOrLoadModel( new ResourceLocation( AppEng.MOD_ID, "part/cable_facade" ) ).getTextures() )
{
event.getMap().registerSprite( location );
}
}
}

View File

@ -53,15 +53,6 @@ public class ColorableTileBlockColor implements IBlockColor
}
}
switch( tintIndex )
{
default:
case 0:
return color.whiteVariant;
case 1:
return color.mediumVariant;
case 2:
return color.blackVariant;
}
return color.getVariantByTintIndex( tintIndex );
}
}

View File

@ -23,16 +23,7 @@ public class StaticItemColor implements IItemColor
@Override
public int getColorFromItemstack( ItemStack stack, int tintIndex )
{
switch( tintIndex )
{
default:
case 0:
return color.whiteVariant;
case 1:
return color.mediumVariant;
case 2:
return color.blackVariant;
}
return color.getVariantByTintIndex( tintIndex );
}
}

View File

@ -0,0 +1,673 @@
package appeng.client.render.cablebus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
import com.google.common.base.Function;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
/**
* A helper class that builds quads for cable connections.
*/
class CableBuilder
{
private final VertexFormat format;
// Textures for the cable core types, one per type/color pair
private final EnumMap<CableCoreType, EnumMap<AEColor, TextureAtlasSprite>> coreTextures;
// Textures for rendering the actual connection cubes, one per type/color pair
private final EnumMap<AECableType, EnumMap<AEColor, TextureAtlasSprite>> connectionTextures;
private final SmartCableTextures smartCableTextures;
CableBuilder( VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
this.format = format;
this.coreTextures = new EnumMap<>( CableCoreType.class );
for( CableCoreType type : CableCoreType.values() )
{
EnumMap<AEColor, TextureAtlasSprite> colorTextures = new EnumMap<>( AEColor.class );
for( AEColor color : AEColor.values() )
{
colorTextures.put( color, bakedTextureGetter.apply( type.getTexture( color ) ) );
}
coreTextures.put( type, colorTextures );
}
this.connectionTextures = new EnumMap<>( AECableType.class );
for( AECableType type : AECableType.VALIDCABLES )
{
EnumMap<AEColor, TextureAtlasSprite> colorTextures = new EnumMap<>( AEColor.class );
for( AEColor color : AEColor.values() )
{
colorTextures.put( color, bakedTextureGetter.apply( type.getConnectionTexture( color ) ) );
}
connectionTextures.put( type, colorTextures );
}
smartCableTextures = new SmartCableTextures( bakedTextureGetter );
}
/**
* Adds the core of a cable to the given list of quads.
*
* The type of cable core is automatically deduced from the given cable type.
*/
public void addCableCore( AECableType cableType, AEColor color, List<BakedQuad> quadsOut )
{
switch( cableType )
{
case GLASS:
addCableCore( CableCoreType.GLASS, color, quadsOut );
break;
case COVERED:
case SMART:
addCableCore( CableCoreType.COVERED, color, quadsOut );
break;
case DENSE:
addCableCore( CableCoreType.DENSE, color, quadsOut );
break;
default:
}
}
public void addCableCore( CableCoreType coreType, AEColor color, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = coreTextures.get( coreType ).get( color );
cubeBuilder.setTexture( texture );
switch( coreType )
{
case GLASS:
cubeBuilder.addCube( 6, 6, 6, 10, 10, 10 );
break;
case COVERED:
cubeBuilder.addCube( 5, 5, 5, 11, 11, 11 );
break;
case DENSE:
cubeBuilder.addCube( 3, 3, 3, 13, 13, 13 );
break;
}
}
public void addGlassConnection( EnumFacing facing, AEColor cableColor, AECableType connectionType, boolean cableBusAdjacent, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces( EnumSet.complementOf( EnumSet.of( facing ) ) );
// For to-machine connections, use a thicker end-cap for the connection
if( connectionType != AECableType.GLASS && !cableBusAdjacent )
{
TextureAtlasSprite texture = connectionTextures.get( AECableType.COVERED ).get( cableColor );
cubeBuilder.setTexture( texture );
addBigCoveredCableSizedCube( facing, cubeBuilder );
}
TextureAtlasSprite texture = connectionTextures.get( AECableType.GLASS ).get( cableColor );
cubeBuilder.setTexture( texture );
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 6, 0, 6, 10, 6, 10 );
break;
case EAST:
cubeBuilder.addCube( 10, 6, 6, 16, 10, 10 );
break;
case NORTH:
cubeBuilder.addCube( 6, 6, 0, 10, 10, 6 );
break;
case SOUTH:
cubeBuilder.addCube( 6, 6, 10, 10, 10, 16 );
break;
case UP:
cubeBuilder.addCube( 6, 10, 6, 10, 16, 10 );
break;
case WEST:
cubeBuilder.addCube( 0, 6, 6, 6, 10, 10 );
break;
}
}
public void addStraightGlassConnection( EnumFacing facing, AEColor cableColor, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
// We render all faces except the connection caps. We can do this because the glass cable is the smallest one
// and its ends will always be covered by something
cubeBuilder.setDrawFaces( EnumSet.complementOf( EnumSet.of( facing, facing.getOpposite() ) ) );
TextureAtlasSprite texture = connectionTextures.get( AECableType.GLASS ).get( cableColor );
cubeBuilder.setTexture( texture );
switch( facing )
{
case DOWN:
case UP:
cubeBuilder.addCube( 6, 0, 6, 10, 16, 10 );
break;
case NORTH:
case SOUTH:
cubeBuilder.addCube( 6, 6, 0, 10, 10, 16 );
break;
case EAST:
case WEST:
cubeBuilder.addCube( 0, 6, 6, 16, 10, 10 );
break;
}
}
public void addConstrainedGlassConnection( EnumFacing facing, AEColor cableColor, int distanceFromEdge, List<BakedQuad> quadsOut )
{
// Glass connections reach only 6 voxels from the edge
if( distanceFromEdge >= 6 )
{
return;
}
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.GLASS ).get( cableColor );
cubeBuilder.setTexture( texture );
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 6, distanceFromEdge, 6, 10, 6, 10 );
break;
case EAST:
cubeBuilder.addCube( 10, 6, 6, 16 - distanceFromEdge, 10, 10 );
break;
case NORTH:
cubeBuilder.addCube( 6, 6, distanceFromEdge, 10, 10, 6 );
break;
case SOUTH:
cubeBuilder.addCube( 6, 6, 10, 10, 10, 16 - distanceFromEdge );
break;
case UP:
cubeBuilder.addCube( 6, 10, 6, 10, 16 - distanceFromEdge, 10 );
break;
case WEST:
cubeBuilder.addCube( distanceFromEdge, 6, 6, 6, 10, 10 );
break;
}
}
public void addCoveredConnection( EnumFacing facing, AEColor cableColor, AECableType connectionType, boolean cableBusAdjacent, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces( EnumSet.complementOf( EnumSet.of( facing ) ) );
TextureAtlasSprite texture = connectionTextures.get( AECableType.COVERED ).get( cableColor );
cubeBuilder.setTexture( texture );
// Draw a covered connection, if anything but glass is requested
if( connectionType != AECableType.GLASS && !cableBusAdjacent )
{
addBigCoveredCableSizedCube( facing, cubeBuilder );
}
addCoveredCableSizedCube( facing, cubeBuilder );
}
public void addStraightCoveredConnection( EnumFacing facing, AEColor cableColor, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.COVERED ).get( cableColor );
cubeBuilder.setTexture( texture );
setStraightCableUVs( cubeBuilder, facing, 5, 11 );
addStraightCoveredCableSizedCube( facing, cubeBuilder );
}
private static void setStraightCableUVs( CubeBuilder cubeBuilder, EnumFacing facing, int x, int y )
{
switch( facing )
{
case DOWN:
case UP:
cubeBuilder.setCustomUv( EnumFacing.NORTH, x, 0, y, x );
cubeBuilder.setCustomUv( EnumFacing.EAST, x, 0, y, x );
cubeBuilder.setCustomUv( EnumFacing.SOUTH, x, 0, y, x );
cubeBuilder.setCustomUv( EnumFacing.WEST, x, 0, y, x );
break;
case EAST:
case WEST:
cubeBuilder.setCustomUv( EnumFacing.UP, 0, x, x, y );
cubeBuilder.setCustomUv( EnumFacing.DOWN, 0, x, x, y );
cubeBuilder.setCustomUv( EnumFacing.NORTH, 0, x, x, y );
cubeBuilder.setCustomUv( EnumFacing.SOUTH, 0, x, x, y );
break;
case NORTH:
case SOUTH:
cubeBuilder.setCustomUv( EnumFacing.UP, x, 0, y, x );
cubeBuilder.setCustomUv( EnumFacing.DOWN, x, 0, y, x );
cubeBuilder.setCustomUv( EnumFacing.EAST, 0, x, x, y );
cubeBuilder.setCustomUv( EnumFacing.WEST, 0, x, x, y );
break;
}
}
public void addConstrainedCoveredConnection( EnumFacing facing, AEColor cableColor, int distanceFromEdge, List<BakedQuad> quadsOut )
{
// The core of a covered cable reaches up to 5 voxels from the block edge, so
// drawing a connection can only occur from there onwards
if( distanceFromEdge >= 5 )
{
return;
}
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.COVERED ).get( cableColor );
cubeBuilder.setTexture( texture );
addCoveredCableSizedCube( facing, distanceFromEdge, cubeBuilder );
}
public void addSmartConnection( EnumFacing facing, AEColor cableColor, AECableType connectionType, boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces( EnumSet.complementOf( EnumSet.of( facing ) ) );
TextureAtlasSprite texture = connectionTextures.get( AECableType.SMART ).get( cableColor );
cubeBuilder.setTexture( texture );
TextureAtlasSprite oddChannel = smartCableTextures.getOddTextureForChannels( channels );
TextureAtlasSprite evenChannel = smartCableTextures.getEvenTextureForChannels( channels );
// For to-machine connections, use a thicker end-cap for the connection
if( connectionType != AECableType.GLASS && !cableBusAdjacent )
{
addBigCoveredCableSizedCube( facing, cubeBuilder );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addBigCoveredCableSizedCube( facing, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addBigCoveredCableSizedCube( facing, cubeBuilder );
// Reset back to normal rendering for the rest
cubeBuilder.setRenderFullBright( false );
cubeBuilder.setTexture( texture );
}
addCoveredCableSizedCube( facing, cubeBuilder );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addCoveredCableSizedCube( facing, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addCoveredCableSizedCube( facing, cubeBuilder );
/* TODO: this.setSmartConnectionRotations( of, renderer );
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;*/
}
public void addStraightSmartConnection( EnumFacing facing, AEColor cableColor, int channels, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.SMART ).get( cableColor );
cubeBuilder.setTexture( texture );
setStraightCableUVs( cubeBuilder, facing, 5, 11 );
addStraightCoveredCableSizedCube( facing, cubeBuilder );
TextureAtlasSprite oddChannel = smartCableTextures.getOddTextureForChannels( channels );
TextureAtlasSprite evenChannel = smartCableTextures.getEvenTextureForChannels( channels );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addStraightCoveredCableSizedCube( facing, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addStraightCoveredCableSizedCube( facing, cubeBuilder );
}
public void addConstrainedSmartConnection( EnumFacing facing, AEColor cableColor, int distanceFromEdge, int channels, List<BakedQuad> quadsOut )
{
// Same as with covered cables, the smart cable's core extends up to 5 voxels away from the edge.
// Drawing a connection to any point before that point is fruitless
if( distanceFromEdge >= 5 )
{
return;
}
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.SMART ).get( cableColor );
cubeBuilder.setTexture( texture );
addCoveredCableSizedCube( facing, distanceFromEdge, cubeBuilder );
TextureAtlasSprite oddChannel = smartCableTextures.getOddTextureForChannels( channels );
TextureAtlasSprite evenChannel = smartCableTextures.getEvenTextureForChannels( channels );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addCoveredCableSizedCube( facing, distanceFromEdge, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addCoveredCableSizedCube( facing, distanceFromEdge, cubeBuilder );
}
public void addDenseConnection( EnumFacing facing, AEColor cableColor, AECableType connectionType, boolean cableBusAdjacent, int channels, List<BakedQuad> quadsOut )
{
// Dense cables only render their connections as dense if the adjacent blocks actually wants that
if( connectionType == AECableType.SMART )
{
addSmartConnection( facing, cableColor, connectionType, cableBusAdjacent, channels, quadsOut );
return;
}
else if( connectionType != AECableType.DENSE )
{
addCoveredConnection( facing, cableColor, connectionType, cableBusAdjacent, quadsOut );
return;
}
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
// We render all faces except the one on the connection side
cubeBuilder.setDrawFaces( EnumSet.complementOf( EnumSet.of( facing ) ) );
TextureAtlasSprite texture = connectionTextures.get( AECableType.DENSE ).get( cableColor );
cubeBuilder.setTexture( texture );
addDenseCableSizedCube( facing, cubeBuilder );
// Dense cables show used channels in groups of 4, rounded up
channels = (channels + 3) / 4;
TextureAtlasSprite oddChannel = smartCableTextures.getOddTextureForChannels( channels );
TextureAtlasSprite evenChannel = smartCableTextures.getEvenTextureForChannels( channels );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addDenseCableSizedCube( facing, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addDenseCableSizedCube( facing, cubeBuilder );
// Reset back to normal rendering for the rest
cubeBuilder.setRenderFullBright( false );
cubeBuilder.setTexture( texture );
}
public void addStraightDenseConnection( EnumFacing facing, AEColor cableColor, int channels, List<BakedQuad> quadsOut )
{
CubeBuilder cubeBuilder = new CubeBuilder( format, quadsOut );
TextureAtlasSprite texture = connectionTextures.get( AECableType.DENSE ).get( cableColor );
cubeBuilder.setTexture( texture );
setStraightCableUVs( cubeBuilder, facing, 5, 11 );
addStraightDenseCableSizedCube( facing, cubeBuilder );
// Dense cables show used channels in groups of 4, rounded up
channels = (channels + 3) / 4;
TextureAtlasSprite oddChannel = smartCableTextures.getOddTextureForChannels( channels );
TextureAtlasSprite evenChannel = smartCableTextures.getEvenTextureForChannels( channels );
// Render the channel indicators brightly lit at night
cubeBuilder.setRenderFullBright( true );
cubeBuilder.setTexture( oddChannel );
cubeBuilder.setColorRGB( cableColor.blackVariant );
addStraightDenseCableSizedCube( facing, cubeBuilder );
cubeBuilder.setTexture( evenChannel );
cubeBuilder.setColorRGB( cableColor.whiteVariant );
addStraightDenseCableSizedCube( facing, cubeBuilder );
}
private static void addDenseCableSizedCube( EnumFacing facing, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 4, 0, 4, 12, 5, 12 );
break;
case EAST:
cubeBuilder.addCube( 11, 4, 4, 16, 12, 12 );
break;
case NORTH:
cubeBuilder.addCube( 4, 4, 0, 12, 12, 5 );
break;
case SOUTH:
cubeBuilder.addCube( 4, 4, 11, 12, 12, 16 );
break;
case UP:
cubeBuilder.addCube( 4, 11, 4, 12, 16, 12 );
break;
case WEST:
cubeBuilder.addCube( 0, 4, 4, 5, 12, 12 );
break;
}
}
// Adds a cube to the given cube builder that has the size of a dense cable connection and spans the entire block for the given direction
private static void addStraightDenseCableSizedCube( EnumFacing facing, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
case UP:
cubeBuilder.addCube( 3, 0, 3, 13, 16, 13 );
break;
case EAST:
case WEST:
/*renderer.uvRotateEast = renderer.uvRotateWest = 1;
renderer.uvRotateBottom = renderer.uvRotateTop = 1;*/
cubeBuilder.addCube( 0, 3, 3, 16, 13, 13 );
break;
case NORTH:
case SOUTH:
// TODO renderer.uvRotateNorth = renderer.uvRotateSouth = 1;
cubeBuilder.addCube( 3, 3, 0, 13, 13, 16 );
break;
}
}
// Adds a cube to the given cube builder that has the size of a covered cable connection from the core of the cable to the given face
private static void addCoveredCableSizedCube( EnumFacing facing, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 6, 0, 6, 10, 5, 10 );
break;
case EAST:
cubeBuilder.addCube( 11, 6, 6, 16, 10, 10 );
break;
case NORTH:
cubeBuilder.addCube( 6, 6, 0, 10, 10, 5 );
break;
case SOUTH:
cubeBuilder.addCube( 6, 6, 11, 10, 10, 16 );
break;
case UP:
cubeBuilder.addCube( 6, 11, 6, 10, 16, 10 );
break;
case WEST:
cubeBuilder.addCube( 0, 6, 6, 5, 10, 10 );
break;
}
}
// Adds a cube to the given cube builder that has the size of a covered cable connection and spans the entire block for the given direction
private static void addStraightCoveredCableSizedCube( EnumFacing facing, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
case UP:
cubeBuilder.addCube( 5, 0, 5, 11, 16, 11 );
break;
case EAST:
case WEST:
/*renderer.uvRotateEast = renderer.uvRotateWest = 1;
renderer.uvRotateBottom = renderer.uvRotateTop = 1;*/
cubeBuilder.addCube( 0, 5, 5, 16, 11, 11 );
break;
case NORTH:
case SOUTH:
// TODO renderer.uvRotateNorth = renderer.uvRotateSouth = 1;
cubeBuilder.addCube( 5, 5, 0, 11, 11, 16 );
break;
}
}
private static void addCoveredCableSizedCube( EnumFacing facing, int distanceFromEdge, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 6, distanceFromEdge, 6, 10, 5, 10 );
break;
case EAST:
cubeBuilder.addCube( 11, 6, 6, 16 - distanceFromEdge, 10, 10 );
break;
case NORTH:
cubeBuilder.addCube( 6, 6, distanceFromEdge, 10, 10, 5 );
break;
case SOUTH:
cubeBuilder.addCube( 6, 6, 11, 10, 10, 16 - distanceFromEdge );
break;
case UP:
cubeBuilder.addCube( 6, 11, 6, 10, 16 - distanceFromEdge, 10 );
break;
case WEST:
cubeBuilder.addCube( distanceFromEdge, 6, 6, 5, 10, 10 );
break;
}
}
/**
* This renders a slightly bigger covered cable connection to the specified side. This is used to connect cable cores with adjacent machines
* that do not want to be connected to using a glass cable connection. This applies to most machines (interfaces, etc.)
*/
private void addBigCoveredCableSizedCube( EnumFacing facing, CubeBuilder cubeBuilder )
{
switch( facing )
{
case DOWN:
cubeBuilder.addCube( 5, 0, 5, 11, 4, 11 );
break;
case EAST:
cubeBuilder.addCube( 12, 5, 5, 16, 11, 11 );
break;
case NORTH:
cubeBuilder.addCube( 5, 5, 0, 11, 11, 4 );
break;
case SOUTH:
cubeBuilder.addCube( 5, 5, 12, 11, 11, 16 );
break;
case UP:
cubeBuilder.addCube( 5, 12, 5, 11, 16, 11 );
break;
case WEST:
cubeBuilder.addCube( 0, 5, 5, 4, 11, 11 );
break;
}
}
// Get all textures needed for building the actual cable quads
public static List<ResourceLocation> getTextures()
{
List<ResourceLocation> locations = new ArrayList<>();
for( CableCoreType coreType : CableCoreType.values() )
{
for( AEColor color : AEColor.values() )
{
locations.add( coreType.getTexture( color ) );
}
}
for( AECableType cableType : AECableType.VALIDCABLES )
{
for( AEColor color : AEColor.values() )
{
locations.add( cableType.getConnectionTexture( color ) );
}
}
Collections.addAll( locations, SmartCableTextures.SMART_CHANNELS_TEXTURES );
return locations;
}
public TextureAtlasSprite getCoreTexture( CableCoreType coreType, AEColor color )
{
return coreTextures.get( coreType ).get( color );
}
}

View File

@ -0,0 +1,260 @@
package appeng.client.render.cablebus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
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 net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.property.IExtendedBlockState;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.block.networking.BlockCableBus;
public class CableBusBakedModel implements IBakedModel
{
private final CableBuilder cableBuilder;
private final Map<ResourceLocation, IBakedModel> partModels;
CableBusBakedModel( CableBuilder cableBuilder, Map<ResourceLocation, IBakedModel> partModels )
{
this.cableBuilder = cableBuilder;
this.partModels = partModels;
}
@Override
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
{
CableBusRenderState renderState = getRenderingState( state );
if( renderState == null || side != null )
{
return Collections.emptyList();
}
// First, handle the cable at the center of the cable bus
List<BakedQuad> quads = new ArrayList<>();
addCableQuads( renderState, quads );
for( EnumFacing facing : EnumFacing.values() )
{
List<ResourceLocation> models = renderState.getAttachments().get( facing );
if( models == null )
{
continue;
}
for( ResourceLocation model : models )
{
IBakedModel bakedModel = partModels.get( model );
if( bakedModel == null )
{
throw new IllegalStateException( "Trying to use an unregistered part model: " + model );
}
List<BakedQuad> partQuads = bakedModel.getQuads( state, null, rand );
// Rotate quads accordingly
QuadRotator rotator = new QuadRotator();
partQuads = rotator.rotateQuads( partQuads, facing, EnumFacing.UP );
quads.addAll( partQuads );
}
}
return quads;
}
// Determines whether a cable is connected to exactly two sides that are opposite each other
private static boolean isStraightLine( Set<EnumFacing> sides )
{
Iterator<EnumFacing> it = sides.iterator();
if( !it.hasNext() )
{
return false; // No connections
}
EnumFacing firstSide = it.next();
if( !it.hasNext() )
{
return false; // Only a single connection
}
if( firstSide.getOpposite() != it.next() )
{
return false; // Connected to two sides that are not opposite each other
}
return !it.hasNext(); // Must not have any other connection points
}
private void addCableQuads( CableBusRenderState renderState, List<BakedQuad> quadsOut )
{
AECableType cableType = renderState.getCableType();
if( cableType == AECableType.NONE )
{
return;
}
AEColor cableColor = renderState.getCableColor();
EnumMap<EnumFacing, AECableType> connectionTypes = renderState.getConnectionTypes();
// If the connection is straight, no busses are attached, and no overed core has been forced (in case of glass
// cables), then render the cable as a simplified straight line.
boolean noAttachments = renderState.getAttachments().isEmpty();
if( isStraightLine( connectionTypes.keySet() ) && noAttachments )
{
EnumFacing facing = connectionTypes.keySet().iterator().next();
switch (cableType) {
case GLASS:
cableBuilder.addStraightGlassConnection( facing, cableColor, quadsOut );
break;
case COVERED:
cableBuilder.addStraightCoveredConnection( facing, cableColor, quadsOut );
break;
case SMART:
cableBuilder.addStraightSmartConnection( facing, cableColor, renderState.getChannelsOnSide().get(facing), quadsOut );
break;
case DENSE:
cableBuilder.addStraightDenseConnection( facing, cableColor, renderState.getChannelsOnSide().get(facing), quadsOut );
break;
}
return; // Don't render the other form of connection
}
cableBuilder.addCableCore( renderState.getCoreType(), cableColor, quadsOut );
// Render all internal connections to attachments
EnumMap<EnumFacing, Integer> attachmentConnections = renderState.getAttachmentConnections();
for( EnumFacing facing : attachmentConnections.keySet() )
{
int distance = attachmentConnections.get( facing );
int channels = renderState.getChannelsOnSide().get( facing );
switch( cableType )
{
case GLASS:
cableBuilder.addConstrainedGlassConnection( facing, cableColor, distance, quadsOut );
break;
case COVERED:
cableBuilder.addConstrainedCoveredConnection( facing, cableColor, distance, quadsOut );
break;
case SMART:
cableBuilder.addConstrainedSmartConnection( facing, cableColor, distance, channels, quadsOut );
break;
case DENSE:
// Dense cables do not render connections to parts since none can be attached
break;
}
}
// Render all outgoing connections using the appropriate type
for( EnumFacing facing : connectionTypes.keySet() )
{
AECableType connectionType = connectionTypes.get( facing );
boolean cableBusAdjacent = renderState.getCableBusAdjacent().contains( facing );
int channels = renderState.getChannelsOnSide().get( facing );
switch( cableType )
{
case GLASS:
cableBuilder.addGlassConnection( facing, cableColor, connectionType, cableBusAdjacent, quadsOut );
break;
case COVERED:
cableBuilder.addCoveredConnection( facing, cableColor, connectionType, cableBusAdjacent, quadsOut );
break;
case SMART:
cableBuilder.addSmartConnection( facing, cableColor, connectionType, cableBusAdjacent, channels, quadsOut );
break;
case DENSE:
cableBuilder.addDenseConnection( facing, cableColor, connectionType, cableBusAdjacent, channels, quadsOut );
break;
}
}
}
/**
* Gets a list of texture sprites appropriate for particles (digging, etc.) given the render state for a cable bus.
*/
public List<TextureAtlasSprite> getParticleTextures( CableBusRenderState renderState )
{
CableCoreType coreType = renderState.getCableType().getCoreType();
AEColor cableColor = renderState.getCableColor();
if( coreType != null )
{
return Collections.singletonList( cableBuilder.getCoreTexture( coreType, cableColor ) );
}
else
{
return Collections.emptyList();
}
// TODO: Add break particles even for the attachments, not just the cable
}
private static CableBusRenderState getRenderingState( IBlockState state )
{
if( state == null || !( state instanceof IExtendedBlockState ) )
{
return null;
}
IExtendedBlockState extendedBlockState = (IExtendedBlockState) state;
return extendedBlockState.getValue( BlockCableBus.RENDER_STATE_PROPERTY );
}
@Override
public boolean isAmbientOcclusion()
{
return false;
}
@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;
}
}

View File

@ -0,0 +1,94 @@
package appeng.client.render.cablebus;
import java.util.Collection;
import java.util.Map;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
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.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import appeng.core.AELog;
import appeng.core.features.registries.PartModels;
/**
* The built-in model for the cable bus block.
*/
public class CableBusModel implements IModel
{
private final PartModels partModels;
public CableBusModel( PartModels partModels )
{
this.partModels = partModels;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
partModels.setInitialized( true );
return partModels.getModels();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return CableBuilder.getTextures();
}
@Override
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
Map<ResourceLocation, IBakedModel> partModels = loadPartModels( state, format, bakedTextureGetter );
CableBuilder cableBuilder = new CableBuilder( format, bakedTextureGetter );
return new CableBusBakedModel( cableBuilder, partModels );
}
private Map<ResourceLocation, IBakedModel> loadPartModels(
IModelState state,
VertexFormat format,
Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
ImmutableMap.Builder<ResourceLocation, IBakedModel> result = ImmutableMap.builder();
for( ResourceLocation location : partModels.getModels() )
{
IModel model = tryLoadPartModel( location );
IBakedModel bakedModel = model.bake( state, format, bakedTextureGetter );
result.put( location, bakedModel );
}
return result.build();
}
private IModel tryLoadPartModel( ResourceLocation location )
{
try
{
return ModelLoaderRegistry.getModel( location );
}
catch( Exception e )
{
AELog.error( e, "Unable to load part model " + location );
return ModelLoaderRegistry.getMissingModel();
}
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
}

View File

@ -0,0 +1,116 @@
package appeng.client.render.cablebus;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
/**
* This class captures the entire rendering state needed for a cable bus and transports it to the rendering thread
* for processing.
*/
public class CableBusRenderState
{
// The cable type used for rendering the outgoing connections to other blocks and attached parts
private AECableType cableType = AECableType.NONE;
// The type to use for rendering the core of the cable.
private CableCoreType coreType;
private AEColor cableColor = AEColor.Transparent;
// Describes the outgoing connections of this cable bus to other blocks, and how they should be rendered
private EnumMap<EnumFacing, AECableType> connectionTypes = new EnumMap<>( EnumFacing.class );
// Indicate on which sides signified by connectionTypes above, there is another cable bus. If a side is connected, but it is absent from this
// set, then it means that there is a Grid host, but not a cable bus on that side (i.e. an interface, a controller, etc.)
private EnumSet<EnumFacing> cableBusAdjacent = EnumSet.noneOf( EnumFacing.class );
// Specifies the number of channels used for the connection to a given side. Only contains entries if
// connections contains a corresponding entry.
private EnumMap<EnumFacing, Integer> channelsOnSide = new EnumMap<>( EnumFacing.class );
private EnumMap<EnumFacing, List<ResourceLocation>> attachments = new EnumMap<>( EnumFacing.class );
// For each attachment, this contains the distance from the edge until which a cable connection should be drawn
private EnumMap<EnumFacing, Integer> attachmentConnections = new EnumMap<>( EnumFacing.class );
public CableCoreType getCoreType()
{
return coreType;
}
public void setCoreType( CableCoreType coreType )
{
this.coreType = coreType;
}
public AECableType getCableType()
{
return cableType;
}
public void setCableType( AECableType cableType )
{
this.cableType = cableType;
}
public AEColor getCableColor()
{
return cableColor;
}
public void setCableColor( AEColor cableColor )
{
this.cableColor = cableColor;
}
public EnumMap<EnumFacing, Integer> getChannelsOnSide()
{
return channelsOnSide;
}
public EnumMap<EnumFacing, AECableType> getConnectionTypes()
{
return connectionTypes;
}
public void setConnectionTypes( EnumMap<EnumFacing, AECableType> connectionTypes )
{
this.connectionTypes = connectionTypes;
}
public void setChannelsOnSide( EnumMap<EnumFacing, Integer> channelsOnSide )
{
this.channelsOnSide = channelsOnSide;
}
public EnumSet<EnumFacing> getCableBusAdjacent()
{
return cableBusAdjacent;
}
public void setCableBusAdjacent( EnumSet<EnumFacing> cableBusAdjacent )
{
this.cableBusAdjacent = cableBusAdjacent;
}
public EnumMap<EnumFacing, List<ResourceLocation>> getAttachments()
{
return attachments;
}
public EnumMap<EnumFacing, Integer> getAttachmentConnections()
{
return attachmentConnections;
}
}

View File

@ -0,0 +1,35 @@
package appeng.client.render.cablebus;
import net.minecraft.util.ResourceLocation;
import appeng.api.util.AEColor;
import appeng.core.AppEng;
/**
* AE can render the core of a cable (the core that connections are made to, in case the cable is not a straight line)
* in three different ways:
* - Glass
* - Covered (also used by the Smart Cable)
* - Dense
*/
public enum CableCoreType
{
GLASS( "parts/cable/core/glass" ),
COVERED( "parts/cable/core/covered" ),
DENSE( "parts/cable/core/dense" );
private final String textureFolder;
CableCoreType( String textureFolder )
{
this.textureFolder = textureFolder;
}
public ResourceLocation getTexture( AEColor color )
{
return new ResourceLocation( AppEng.MOD_ID, textureFolder + "/" + color.name().toLowerCase() );
}
}

View File

@ -0,0 +1,275 @@
package appeng.client.render.cablebus;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
import javax.vecmath.Vector4f;
import net.minecraft.client.renderer.block.model.BakedQuad;
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.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
/**
* Builds the quads for a cube.
*/
public class CubeBuilder {
private VertexFormat format;
private final List<BakedQuad> output;
private final EnumMap<EnumFacing, TextureAtlasSprite> textures = new EnumMap<>(EnumFacing.class);
private EnumSet<EnumFacing> drawFaces = EnumSet.allOf(EnumFacing.class);
private final EnumMap<EnumFacing, Vector4f> customUv = new EnumMap<>(EnumFacing.class);
private int color = 0xFFFFFFFF;
private boolean renderFullBright;
public CubeBuilder(VertexFormat format, List<BakedQuad> output) {
this.output = output;
this.format = format;
}
public CubeBuilder(VertexFormat format) {
this(format, new ArrayList<>(6));
}
public void addCube(float x1, float y1, float z1, float x2, float y2, float z2) {
x1 /= 16.0f;
y1 /= 16.0f;
z1 /= 16.0f;
x2 /= 16.0f;
y2 /= 16.0f;
z2 /= 16.0f;
// If brightness is forced to specific values, extend the vertex format to contain the multi-texturing lightmap offset
VertexFormat savedFormat = null;
if (renderFullBright) {
savedFormat = format;
format = new VertexFormat(savedFormat);
if (!format.getElements().contains(DefaultVertexFormats.TEX_2S)) {
format.addElement(DefaultVertexFormats.TEX_2S);
}
}
for (EnumFacing face : drawFaces) {
putFace(face, x1, y1, z1, x2, y2, z2);
}
// Restore old format
if (savedFormat != null) {
format = savedFormat;
}
}
private void putFace(EnumFacing face,
float x1, float y1, float z1,
float x2, float y2, float z2
) {
TextureAtlasSprite texture = textures.get(face);
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setTexture(texture);
builder.setQuadOrientation(face);
float u1 = 0;
float v1 = 0;
float u2 = 0;
float v2 = 0;
// The user might have set specific UV coordinates for this face
Vector4f customUv = this.customUv.get( face );
if( customUv != null )
{
u1 = texture.getInterpolatedU( customUv.x );
v1 = texture.getInterpolatedV( customUv.y );
u2 = texture.getInterpolatedU( customUv.z );
v2 = texture.getInterpolatedV( customUv.w );
}
switch (face) {
case DOWN:
if (customUv == null)
{
u1 = texture.getInterpolatedU( x1 * 16 );
v1 = texture.getInterpolatedV( z1 * 16 );
u2 = texture.getInterpolatedU( x2 * 16 );
v2 = texture.getInterpolatedV( z2 * 16 );
}
putVertex(builder, face, x2, y1, z1, u2, v1);
putVertex(builder, face, x2, y1, z2, u2, v2);
putVertex(builder, face, x1, y1, z2, u1, v2);
putVertex(builder, face, x1, y1, z1, u1, v1);
break;
case UP:
if (customUv == null)
{
u1 = texture.getInterpolatedU( x1 * 16 );
v1 = texture.getInterpolatedV( z1 * 16 );
u2 = texture.getInterpolatedU( x2 * 16 );
v2 = texture.getInterpolatedV( z2 * 16 );
}
putVertex(builder, face, x1, y2, z1, u1, v1);
putVertex(builder, face, x1, y2, z2, u1, v2);
putVertex(builder, face, x2, y2, z2, u2, v2);
putVertex(builder, face, x2, y2, z1, u2, v1);
break;
case NORTH:
if (customUv == null)
{
u1 = texture.getInterpolatedU( x1 * 16 );
v1 = texture.getInterpolatedV( 16 - y1 * 16 );
u2 = texture.getInterpolatedU( x2 * 16 );
v2 = texture.getInterpolatedV( 16 - y2 * 16 );
}
putVertex(builder, face, x2, y2, z1, u1, v2);
putVertex(builder, face, x2, y1, z1, u1, v1);
putVertex(builder, face, x1, y1, z1, u2, v1);
putVertex(builder, face, x1, y2, z1, u2, v2);
break;
case SOUTH:
if (customUv == null)
{
u1 = texture.getInterpolatedU( x1 * 16 );
v1 = texture.getInterpolatedV( 16 - y1 * 16 );
u2 = texture.getInterpolatedU( x2 * 16 );
v2 = texture.getInterpolatedV( 16 - y2 * 16 );
}
putVertex(builder, face, x1, y2, z2, u1, v2);
putVertex(builder, face, x1, y1, z2, u1, v1);
putVertex(builder, face, x2, y1, z2, u2, v1);
putVertex(builder, face, x2, y2, z2, u2, v2);
break;
case WEST:
if (customUv == null)
{
u1 = texture.getInterpolatedU( z1 * 16 );
v1 = texture.getInterpolatedV( 16 - y1 * 16 );
u2 = texture.getInterpolatedU( z2 * 16 );
v2 = texture.getInterpolatedV( 16 - y2 * 16 );
}
putVertex(builder, face, x1, y1, z1, u1, v1);
putVertex(builder, face, x1, y1, z2, u2, v1);
putVertex(builder, face, x1, y2, z2, u2, v2);
putVertex(builder, face, x1, y2, z1, u1, v2);
break;
case EAST:
if (customUv == null)
{
u1 = texture.getInterpolatedU( z2 * 16 );
v1 = texture.getInterpolatedV( 16 - y1 * 16 );
u2 = texture.getInterpolatedU( z1 * 16 );
v2 = texture.getInterpolatedV( 16 - y2 * 16 );
}
putVertex(builder, face, x2, y2, z1, u1, v2);
putVertex(builder, face, x2, y2, z2, u2, v2);
putVertex(builder, face, x2, y1, z2, u2, v1);
putVertex(builder, face, x2, y1, z1, u1, v1);
break;
}
int[] vertexData = builder.build().getVertexData();
output.add(new BakedQuad(vertexData, -1, face, texture, true, format));
}
private void putVertex(UnpackedBakedQuad.Builder builder, EnumFacing face, float x, float y, float z, float u, float v) {
VertexFormat format = builder.getVertexFormat();
for (int i = 0; i < format.getElementCount(); i++) {
VertexFormatElement e = format.getElement(i);
switch (e.getUsage()) {
case POSITION:
builder.put(i, x, y, z);
break;
case NORMAL:
builder.put(i,
face.getFrontOffsetX(),
face.getFrontOffsetY(),
face.getFrontOffsetZ());
break;
case COLOR:
// Color format is RGBA
float r = (color >> 16 & 0xFF) / 255f;
float g = (color >> 8 & 0xFF) / 255f;
float b = (color & 0xFF) / 255f;
float a = (color >> 24 & 0xFF) / 255f;
builder.put(i, r, g, b, a);
break;
case UV:
if (e.getIndex() == 0) {
builder.put(i, u, v);
} else {
// Force Brightness to 15, this is for full bright mode
// this vertex element will only be present in that case
final float lightMapU = (float) (15 * 0x20) / 0xFFFF;
final float lightMapV = (float) (15 * 0x20) / 0xFFFF;
builder.put(i, lightMapU, lightMapV);
}
break;
default:
builder.put(i);
break;
}
}
}
public void setTexture(TextureAtlasSprite texture) {
for (EnumFacing face : EnumFacing.values()) {
textures.put(face, texture);
}
}
public void setTextures(TextureAtlasSprite up, TextureAtlasSprite down, TextureAtlasSprite north, TextureAtlasSprite south, TextureAtlasSprite east, TextureAtlasSprite west) {
textures.put(EnumFacing.UP, up);
textures.put(EnumFacing.DOWN, down);
textures.put(EnumFacing.NORTH, north);
textures.put(EnumFacing.SOUTH, south);
textures.put(EnumFacing.EAST, east);
textures.put(EnumFacing.WEST, west);
}
public void setDrawFaces(EnumSet<EnumFacing> drawFaces) {
this.drawFaces = drawFaces;
}
public void setColor(int color) {
this.color = color;
}
/**
* Sets the vertex color for future vertices to the given RGB value, and forces the alpha component to 255.
*/
public void setColorRGB(int color) {
setColor(color | 0xFF000000);
}
public void setRenderFullBright(boolean renderFullBright) {
this.renderFullBright = renderFullBright;
}
public void setCustomUv( EnumFacing facing, float u1, float v1, float u2, float v2 )
{
customUv.put( facing, new Vector4f( u1, v1, u2, v2 ) );
}
public List<BakedQuad> getOutput() {
return output;
}
}

View File

@ -0,0 +1,169 @@
package appeng.client.render.cablebus;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import appeng.client.render.FacingToRotation;
import appeng.core.AELog;
/**
* Assuming a default-orientation of forward=NORTH and up=UP, this class rotates a given list of quads to the desired facing
*/
public class QuadRotator
{
public List<BakedQuad> rotateQuads( List<BakedQuad> quads, EnumFacing newForward, EnumFacing newUp )
{
if( newForward == EnumFacing.NORTH && newUp == EnumFacing.UP )
{
return quads; // This is the default orientation
}
List<BakedQuad> result = new ArrayList<>( quads.size() );
for( BakedQuad quad : quads )
{
result.add( rotateQuad( quad, newForward, newUp ) );
}
return result;
}
private BakedQuad rotateQuad( BakedQuad quad, EnumFacing forward, EnumFacing up )
{
// Sanitize forward/up
if (forward.getAxis() == up.getAxis()) {
if (up.getAxis() == EnumFacing.Axis.Y) {
up = EnumFacing.NORTH;
} else {
up = EnumFacing.UP;
}
}
FacingToRotation rotation = FacingToRotation.get( forward, up );
Matrix4f mat = rotation.getMat();
// Clone the vertex data used by the quad
int[] newData = quad.getVertexData().clone();
// Figure out where the position is in the array
VertexFormat format = quad.getFormat();
int posIdx = findPositionOffset( format ) / 4;
int stride = format.getNextOffset() / 4;
int normalIdx = format.getNormalOffset();
VertexFormatElement.EnumType normalType = null;
// Figure out the type of the normals
if( normalIdx != -1 )
{
for( int i = 0; i < format.getElements().size(); i++ )
{
VertexFormatElement element = format.getElement( i );
if( element.getUsage() == VertexFormatElement.EnumUsage.NORMAL )
{
normalType = element.getType();
}
}
}
for( int i = 0; i < 4; i++ )
{
Point3f pos = new Point3f(
Float.intBitsToFloat( newData[i * stride + posIdx] ) - 0.5f,
Float.intBitsToFloat( newData[i * stride + posIdx + 1] ) - 0.5f,
Float.intBitsToFloat( newData[i * stride + posIdx + 2] ) - 0.5f
);
// Rotate stuff around
mat.transform( pos );
// Write back
newData[i * stride + posIdx] = Float.floatToIntBits( pos.getX() + 0.5f );
newData[i * stride + posIdx + 1] = Float.floatToIntBits( pos.getY() + 0.5f );
newData[i * stride + posIdx + 2] = Float.floatToIntBits( pos.getZ() + 0.5f );
// Transform the normal if one is present
if ( normalIdx != -1 ) {
if( normalType == VertexFormatElement.EnumType.FLOAT )
{
Vector3f normal = new Vector3f(
Float.intBitsToFloat( newData[i * stride + normalIdx] ),
Float.intBitsToFloat( newData[i * stride + normalIdx + 1] ),
Float.intBitsToFloat( newData[i * stride + normalIdx + 2] )
);
// Rotate stuff around
mat.transform( normal );
// Write back
newData[i * stride + normalIdx] = Float.floatToIntBits( normal.getX() );
newData[i * stride + normalIdx + 1] = Float.floatToIntBits( normal.getY() );
newData[i * stride + normalIdx + 2] = Float.floatToIntBits( normal.getZ() );
}
else if( normalType == VertexFormatElement.EnumType.BYTE )
{
int idx = i * stride * 4 + normalIdx;
Vector3f normal = new Vector3f( getByte( newData, idx ) / 127.0f, getByte( newData, idx + 1 ) / 127.0f, getByte( newData, idx + 2 ) / 127.0f );
// Rotate stuff around
mat.transform( normal );
// Write back
setByte( newData, idx, (int) ( normal.getX() * 127 ) );
setByte( newData, idx + 1, (int) ( normal.getY() * 127 ) );
setByte( newData, idx + 2, (int) ( normal.getZ() * 127 ) );
}
else
{
AELog.warn( "Unsupported normal format: {}", normalType );
}
}
}
EnumFacing newFace = rotation.rotate( quad.getFace() );
return new BakedQuad( newData, quad.getTintIndex(), newFace, quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat() );
}
private static int getByte( int[] data, int offset )
{
int idx = offset / 4;
int subOffset = offset % 4;
return (byte) ( data[idx] >> ( subOffset * 8 ) );
}
private static void setByte( int[] data, int offset, int value )
{
int idx = offset / 4;
int subOffset = offset % 4;
int mask = 0xFF << ( subOffset * 8 );
data[idx] = data[idx] & ( ~mask ) | ( (value & 0xFF) << (subOffset * 8) );
}
private int findPositionOffset( VertexFormat format )
{
List<VertexFormatElement> elements = format.getElements();
for( int i = 0; i < elements.size(); i++ )
{
VertexFormatElement e = elements.get( i );
if( e.isPositionElement() )
{
if( e.getType() != VertexFormatElement.EnumType.FLOAT )
{
throw new IllegalArgumentException( "Only floating point positions are supported" );
}
return i;
}
}
throw new IllegalArgumentException( "Vertex format " + format + " has no position attribute!" );
}
}

View File

@ -0,0 +1,81 @@
package appeng.client.render.cablebus;
import java.util.Arrays;
import com.google.common.base.Function;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
/**
* Manages the channel textures for smart cables.
*/
public class SmartCableTextures
{
public static final ResourceLocation[] SMART_CHANNELS_TEXTURES = {
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_00" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_01" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_02" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_03" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_04" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_10" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_11" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_12" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_13" ),
new ResourceLocation( AppEng.MOD_ID, "parts/cable/smart/channels_14" )
};
// Textures used to display channels on smart cables. There's two sets of 5 textures each, and
// one of each set are composed together to get even/odd colored channels
private final TextureAtlasSprite[] textures;
public SmartCableTextures( Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
textures = Arrays.stream( SMART_CHANNELS_TEXTURES )
.map( bakedTextureGetter::apply )
.toArray( TextureAtlasSprite[]::new );
}
/**
* The odd variant is used for displaying channels 1-4 as in use.
*/
public TextureAtlasSprite getOddTextureForChannels( int channels )
{
if( channels < 0 )
{
return textures[0];
}
else if( channels <= 4 )
{
return textures[channels];
}
else
{
return textures[4];
}
}
/**
* The odd variant is used for displaying channels 5-8 as in use.
*/
public TextureAtlasSprite getEvenTextureForChannels( int channels )
{
if( channels < 5 )
{
return textures[5];
}
else if( channels <= 9 )
{
return textures[channels];
}
else
{
return textures[9];
}
}
}

View File

@ -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;
}
}

View File

@ -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 );
}
}
}

View File

@ -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 ) );
}
}

View File

@ -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 );
}
}

View File

@ -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();
}
}

View File

@ -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
{

View File

@ -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();
}
}

View File

@ -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;
}
}
}

View File

@ -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 );
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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 );
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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() );
}
};
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -29,6 +29,7 @@ import appeng.api.storage.IStorageHelper;
import appeng.api.util.AEPartLocation;
import appeng.core.api.ApiPart;
import appeng.core.api.ApiStorage;
import appeng.core.features.registries.PartModels;
import appeng.core.features.registries.RegistryContainer;
import appeng.me.GridConnection;
import appeng.me.GridNode;
@ -51,7 +52,7 @@ public final class Api implements IAppEngApi
this.storageHelper = new ApiStorage();
this.registryContainer = new RegistryContainer();
this.partHelper = new ApiPart();
this.definitions = new ApiDefinitions( this.partHelper );
this.definitions = new ApiDefinitions( (PartModels) this.registryContainer.partModels() );
}
@Override

View File

@ -20,12 +20,12 @@ package appeng.core;
import appeng.api.definitions.IDefinitions;
import appeng.api.parts.IPartHelper;
import appeng.bootstrap.FeatureFactory;
import appeng.core.api.definitions.ApiBlocks;
import appeng.core.api.definitions.ApiItems;
import appeng.core.api.definitions.ApiMaterials;
import appeng.core.api.definitions.ApiParts;
import appeng.core.features.registries.PartModels;
/**
@ -40,12 +40,12 @@ public final class ApiDefinitions implements IDefinitions
private final FeatureFactory registry = new FeatureFactory();
public ApiDefinitions( final IPartHelper partHelper )
public ApiDefinitions( final PartModels partModels )
{
this.blocks = new ApiBlocks( registry );
this.blocks = new ApiBlocks( registry, partModels );
this.items = new ApiItems( registry );
this.materials = new ApiMaterials( registry );
this.parts = new ApiParts( registry, partHelper );
this.parts = new ApiParts( registry, partModels );
}
public FeatureFactory getRegistry()

View File

@ -20,11 +20,12 @@ package appeng.core;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.FMLCommonHandler;
@ -41,6 +42,7 @@ import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import appeng.api.AEApi;
import appeng.core.crash.CrashInfo;
import appeng.core.crash.IntegrationCrashEnhancement;
import appeng.core.crash.ModCrashEnhancement;
@ -169,6 +171,12 @@ public final class AppEng
}
AELog.info( "Pre Initialization ( ended after " + watch.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
// Instantiate all Plugins
List<Object> injectables = Lists.newArrayList(
AEApi.instance()
);
new PluginLoader().loadPlugins( injectables, event.getAsmData() );
}
private void startService( final String serviceName, final Thread thread )

View File

@ -25,7 +25,6 @@ import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.SidedProxy;
@ -60,7 +59,7 @@ public abstract class CommonHelper
public abstract RayTraceResult getRTR();
public abstract void doRenderItem( ItemStack itemstack, World w );
public abstract void doRenderItem( ItemStack itemstack );
public abstract void postInit();

View File

@ -0,0 +1,146 @@
package appeng.core;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableMap;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import appeng.api.AEInjectable;
import appeng.api.AEPlugin;
import appeng.api.exceptions.AppEngException;
/**
* Loads AE plugins on startup and provides them with access to various components of the AE API.
*/
class PluginLoader
{
public void loadPlugins( Collection<Object> injectables, ASMDataTable asmDataTable )
{
Map<Class<?>, Object> injectableMap = mapInjectables( injectables );
findAndInstantiatePlugins( asmDataTable, injectableMap );
}
private static void findAndInstantiatePlugins( ASMDataTable dataTable, Map<Class<?>, Object> injectableMap )
{
Set<ASMDataTable.ASMData> allAnnotated = dataTable.getAll( AEPlugin.class.getCanonicalName() );
for( ASMDataTable.ASMData candidate : allAnnotated )
{
Class<?> aClass;
try
{
aClass = Class.forName( candidate.getClassName() );
}
catch( ClassNotFoundException e )
{
AELog.error( e, "Couldn't find annotated AE plugin class " + candidate.getClassName() );
throw new RuntimeException( "Couldn't find annotated AE plugin class " + candidate.getClassName(), e );
}
// Try instantiating the plugin
try
{
Object plugin = instantiatePlugin( aClass, injectableMap );
AELog.info( "Loaded AE2 Plugin {}", plugin.getClass() );
}
catch( Exception e )
{
AELog.error( e, "Unable to instantiate AE plugin " + candidate.getClassName() );
throw new RuntimeException( "Unable to instantiate AE plugin " + candidate.getClassName(), e );
}
}
}
private static Object instantiatePlugin( Class<?> aClass, Map<Class<?>, Object> injectableMap ) throws Exception
{
Constructor<?>[] constructors = aClass.getDeclaredConstructors();
if( constructors.length == 0 )
{
// This is the default no-arg constructor, although it seems pointless to instantiate anything but not take any AE dependencies as parameters
return aClass.newInstance();
}
else if( constructors.length != 1 )
{
throw new IllegalArgumentException( "Expected a single constructor, but found: " + constructors.length );
}
Constructor<?> constructor = constructors[0];
constructor.setAccessible( true );
Object[] args = findInjectables( constructor, injectableMap );
return constructor.newInstance( args );
}
private static Object[] findInjectables( Constructor<?> constructor, Map<Class<?>, Object> injectableMap )
{
Class<?>[] types = constructor.getParameterTypes();
Object[] args = new Object[types.length];
for( int i = 0; i < types.length; i++ )
{
args[i] = injectableMap.get( types[i] );
if( args[i] == null )
{
throw new IllegalArgumentException( "Constructor has parameter of type " + types[i] + " which is not an injectable type."
+ " Please see the documentation for @AEPlugin." );
}
}
return args;
}
private static Map<Class<?>, Object> mapInjectables( Collection<Object> injectables )
{
ImmutableMap.Builder<Class<?>, Object> builder = ImmutableMap.builder();
for( Object injectable : injectables )
{
// Get all super-interfaces that were annotated with @AEInjectable
Set<Class<?>> injectableIfs = getInjectableInterfaces( injectable.getClass() );
for( Class<?> injectableIf : injectableIfs )
{
builder.put( injectableIf, injectable );
}
}
return builder.build();
}
private static Set<Class<?>> getInjectableInterfaces( Class<?> aClass )
{
Set<Class<?>> hierarchy = new HashSet<>();
getFullHierarchy( aClass, hierarchy );
return hierarchy.stream()
.filter( c -> c.getAnnotation( AEInjectable.class ) != null )
.collect( Collectors.toSet() );
}
// Recursively gather all superclasses and superinterfaces of the given class and put them into the given collection
private static void getFullHierarchy( Class<?> aClass, Set<Class<?>> classes )
{
classes.add( aClass );
for( Class<?> anIf : aClass.getInterfaces() )
{
getFullHierarchy( anIf, classes );
}
if( aClass.getSuperclass() != null )
{
getFullHierarchy( aClass.getSuperclass(), classes );
}
}
}

View File

@ -55,7 +55,6 @@ import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.IPartHelper;
import appeng.block.networking.BlockCableBus;
import appeng.core.features.AEFeature;
import appeng.core.features.registries.P2PTunnelRegistry;
import appeng.core.features.registries.entries.BasicCellHandler;
@ -145,7 +144,6 @@ public final class Registration
// Register all detected handlers and features (items, blocks) in pre-init
definitions.getRegistry().getBootstrapComponents().forEach( b -> b.preInitialize( event.getSide() ) );
}
private void registerSpatial( final boolean force )
@ -342,7 +340,6 @@ public final class Registration
GuiText.values();
Api.INSTANCE.partHelper().initFMPSupport();
blocks.multiPart().maybeBlock().ifPresent( block -> ( (BlockCableBus) block ).setupTile() );
definitions.getRegistry().getBootstrapComponents().forEach( b -> b.postInitialize( event.getSide() ) );

View File

@ -57,13 +57,14 @@ import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IFMP;
import appeng.parts.PartPlacement;
import appeng.tile.AEBaseTile;
import appeng.tile.networking.TileCableBus;
public class ApiPart implements IPartHelper
{
private final Map<String, Class> tileImplementations = new HashMap<String, Class>();
private final Map<String, Class<? extends AEBaseTile>> tileImplementations = new HashMap<>();
private final Map<Class<?>, String> interfaces2Layer = new HashMap<Class<?>, String>();
private final Map<String, Class> roots = new HashMap<String, Class>();
private final List<String> desc = new LinkedList<String>();
@ -79,18 +80,13 @@ public class ApiPart implements IPartHelper
}
}
public Class getCombinedInstance( final String base )
public Class<? extends AEBaseTile> getCombinedInstance( final Class<? extends AEBaseTile> baseClass )
{
String base = baseClass.getName();
if( this.desc.isEmpty() )
{
try
{
return Class.forName( base );
}
catch( final ClassNotFoundException e )
{
throw new IllegalStateException( e );
}
return baseClass;
}
final String description = base + ':' + Joiner.on( ";" ).skipNulls().join( this.desc.iterator() );
@ -101,25 +97,8 @@ public class ApiPart implements IPartHelper
}
String f = base;// TileCableBus.class.getName();
String Addendum = "";
try
{
Addendum = Class.forName( base ).getSimpleName();
}
catch( final ClassNotFoundException e )
{
AELog.debug( e );
}
Class myCLass;
try
{
myCLass = Class.forName( f );
}
catch( final ClassNotFoundException e )
{
throw new IllegalStateException( e );
}
String Addendum = baseClass.getSimpleName();
Class<? extends AEBaseTile> myClass = baseClass;
String path = f;
@ -128,21 +107,20 @@ public class ApiPart implements IPartHelper
try
{
final String newPath = path + ';' + name;
myCLass = this.getClassByDesc( Addendum, newPath, f, this.interfaces2Layer.get( Class.forName( name ) ) );
myClass = this.getClassByDesc( baseClass.getSimpleName(), newPath, f, this.interfaces2Layer.get( Class.forName( name ) ) );
path = newPath;
}
catch( final Throwable t )
{
AELog.warn( "Error loading " + name );
AELog.debug( t );
// throw new RuntimeException( t );
}
f = myCLass.getName();
f = myClass.getName();
}
this.tileImplementations.put( description, myCLass );
this.tileImplementations.put( description, myClass );
return myCLass;
return myClass;
}
private Class getClassByDesc( final String addendum, final String fullPath, final String root, final String next )

View File

@ -23,6 +23,7 @@ import net.minecraft.block.BlockDispenser;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
@ -85,6 +86,7 @@ import appeng.bootstrap.IItemRendering;
import appeng.client.render.model.GlassModel;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.features.registries.PartModels;
import appeng.debug.BlockChunkloader;
import appeng.debug.BlockCubeGenerator;
import appeng.debug.BlockItemGen;
@ -101,6 +103,8 @@ import appeng.decorative.solid.BlockSkyStone;
import appeng.decorative.solid.BlockSkyStone.SkystoneType;
import appeng.decorative.stair.BlockStairCommon;
import appeng.hooks.DispenserBehaviorTinyTNT;
import appeng.tile.networking.CableBusTESR;
import appeng.util.Platform;
/**
@ -184,7 +188,7 @@ public final class ApiBlocks implements IBlocks
private final IBlockDefinition phantomNode;
private final IBlockDefinition cubeGenerator;
public ApiBlocks( FeatureFactory registry )
public ApiBlocks( FeatureFactory registry, PartModels partModels )
{
// this.quartzOre = new BlockDefinition( "ore.quartz", new OreQuartz() );
this.quartzOre = registry.block( "quartz_ore", BlockQuartzOre::new )
@ -357,8 +361,15 @@ public final class ApiBlocks implements IBlocks
this.chiseledQuartzStairs = makeStairs( "chiseled_quartz_stairs", registry, this.chiseledQuartzBlock() );
this.quartzPillarStairs = makeStairs( "quartz_pillar_stairs", registry, this.quartzPillar() );
this.multiPart = registry.block( "multipart_block", BlockCableBus::new )
.rendering( new CableBusRendering() )
this.multiPart = registry.block( "cable_bus", BlockCableBus::new )
.rendering( new CableBusRendering( partModels ) )
.postInit( (block, item) -> {
( (BlockCableBus) block ).setupTile();
if( Platform.isClient() )
{
ClientRegistry.bindTileEntitySpecialRenderer( BlockCableBus.getTesrTile(), new CableBusTESR() );
}
} )
.build();
// TODO Re-Add Slabs...

View File

@ -22,13 +22,13 @@ package appeng.core.api.definitions;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IParts;
import appeng.api.exceptions.MissingDefinition;
import appeng.api.parts.IPartHelper;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.bootstrap.FeatureFactory;
import appeng.core.features.ColoredItemDefinition;
import appeng.core.features.DamagedItemDefinition;
import appeng.core.features.ItemStackSrc;
import appeng.core.features.registries.PartModels;
import appeng.items.parts.ItemMultiPart;
import appeng.items.parts.ItemMultipartRendering;
import appeng.items.parts.PartType;
@ -78,13 +78,19 @@ public final class ApiParts implements IParts
private final IItemDefinition storageMonitor;
private final IItemDefinition conversionMonitor;
public ApiParts( FeatureFactory registry, IPartHelper partHelper )
public ApiParts( FeatureFactory registry, PartModels partModels )
{
final ItemMultiPart itemMultiPart = new ItemMultiPart( partHelper );
final ItemMultiPart itemMultiPart = new ItemMultiPart();
registry.item( "multipart", () -> itemMultiPart )
.rendering( new ItemMultipartRendering( itemMultiPart ) )
.rendering( new ItemMultipartRendering( partModels, itemMultiPart ) )
.build();
// Register all part models
for( PartType partType : PartType.values() )
{
partModels.registerModels( partType.getModels() );
}
this.cableSmart = constructColoredDefinition( itemMultiPart, PartType.CableSmart );
this.cableCovered = constructColoredDefinition( itemMultiPart, PartType.CableCovered );
this.cableGlass = constructColoredDefinition( itemMultiPart, PartType.CableGlass );

View File

@ -0,0 +1,40 @@
package appeng.core.features.registries;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.util.ResourceLocation;
import appeng.api.parts.IPartModels;
public class PartModels implements IPartModels
{
private final Set<ResourceLocation> models = new HashSet<>();
private boolean initialized = false;
@Override
public void registerModels( Collection<ResourceLocation> partModels )
{
if( initialized )
{
throw new IllegalStateException( "Cannot register models after the pre-initialization phase!" );
}
models.addAll( partModels );
}
public Set<ResourceLocation> getModels()
{
return models;
}
public void setInitialized( boolean initialized )
{
this.initialized = initialized;
}
}

View File

@ -32,6 +32,7 @@ import appeng.api.features.IWirelessTermRegistry;
import appeng.api.features.IWorldGen;
import appeng.api.movable.IMovableRegistry;
import appeng.api.networking.IGridCacheRegistry;
import appeng.api.parts.IPartModels;
import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IExternalStorageRegistry;
@ -59,6 +60,7 @@ public class RegistryContainer implements IRegistryContainer
private final IMatterCannonAmmoRegistry matterCannonReg = new MatterCannonAmmoRegistry();
private final IPlayerRegistry playerRegistry = new PlayerRegistry();
private final IRecipeHandlerRegistry recipeReg = new RecipeHandlerRegistry();
private final IPartModels partModels = new PartModels();
@Override
public IMovableRegistry movable()
@ -143,4 +145,11 @@ public class RegistryContainer implements IRegistryContainer
{
return WorldGenRegistry.INSTANCE;
}
@Override
public IPartModels partModels()
{
return partModels;
}
}

View File

@ -19,48 +19,20 @@
package appeng.facade;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import javax.annotation.Nullable;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.client.BakingPipeline;
import appeng.api.parts.IBoxProvider;
import appeng.api.parts.IFacadeContainer;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.util.AEPartLocation;
import appeng.client.render.model.ModelsCache;
import appeng.client.render.model.pipeline.MatVecApplicator;
import appeng.client.render.model.pipeline.ParentQuads;
import appeng.client.render.model.pipeline.StatePosRecolorator;
import appeng.client.render.model.pipeline.TypeTransformer;
import appeng.core.AppEng;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IBuildCraftTransport;
@ -193,114 +165,9 @@ public class FacadePart implements IFacadePart, IBoxProvider
return null;
}
private EnumSet<AEPartLocation> calculateFaceOpenFaces( final IBlockAccess blockAccess, final IFacadeContainer fc, final BlockPos pos, final AEPartLocation side )
{
final EnumSet<AEPartLocation> out = EnumSet.of( side, side.getOpposite() );
final IFacadePart facade = fc.getFacade( side );
for( final AEPartLocation it : AEPartLocation.SIDE_LOCATIONS )
{
if( !out.contains( it ) && this.hasAlphaDiff( blockAccess.getTileEntity( pos.offset( it.getFacing() ) ), side, facade ) )
{
out.add( it );
}
}
if( out.contains( AEPartLocation.UP ) && ( side.xOffset != 0 || side.zOffset != 0 ) )
{
final IFacadePart fp = fc.getFacade( AEPartLocation.UP );
if( fp != null && ( fp.isTransparent() == facade.isTransparent() ) )
{
out.remove( AEPartLocation.UP );
}
}
if( out.contains( AEPartLocation.DOWN ) && ( side.xOffset != 0 || side.zOffset != 0 ) )
{
final IFacadePart fp = fc.getFacade( AEPartLocation.DOWN );
if( fp != null && ( fp.isTransparent() == facade.isTransparent() ) )
{
out.remove( AEPartLocation.DOWN );
}
}
if( out.contains( AEPartLocation.SOUTH ) && ( side.xOffset != 0 ) )
{
final IFacadePart fp = fc.getFacade( AEPartLocation.SOUTH );
if( fp != null && ( fp.isTransparent() == facade.isTransparent() ) )
{
out.remove( AEPartLocation.SOUTH );
}
}
if( out.contains( AEPartLocation.NORTH ) && ( side.xOffset != 0 ) )
{
final IFacadePart fp = fc.getFacade( AEPartLocation.NORTH );
if( fp != null && ( fp.isTransparent() == facade.isTransparent() ) )
{
out.remove( AEPartLocation.NORTH );
}
}
/*
* if ( out.contains( AEPartLocation.EAST ) && (side.offsetZ != 0) ) { IFacadePart fp = fc.getFacade(
* AEPartLocation.EAST ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.EAST ); }
* if ( out.contains( AEPartLocation.WEST ) && (side.offsetZ != 0) ) { IFacadePart fp = fc.getFacade(
* AEPartLocation.WEST ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.WEST ); }
* if ( out.contains( AEPartLocation.NORTH ) && (side.offsetY != 0) ) { IFacadePart fp = fc.getFacade(
* AEPartLocation.NORTH ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.NORTH ); }
* if ( out.contains( AEPartLocation.SOUTH ) && (side.offsetY != 0) ) { IFacadePart fp = fc.getFacade(
* AEPartLocation.SOUTH ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.SOUTH ); }
* if ( out.contains( AEPartLocation.EAST ) && (side.offsetY != 0) ) { IFacadePart fp = fc.getFacade(
* AEPartLocation.EAST ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.EAST ); }
* if ( out.contains( AEPartLocation.WEST ) && (side.offsetY != 0) ) { IFacadePart fp = fc.getFacade(s
* AEPartLocation.WEST ); if ( fp != null && (fp.isTransparent() == facade.isTransparent()) ) out.remove(
* AEPartLocation.WEST ); }
*/
return out;
}
private boolean hasAlphaDiff( final TileEntity tileEntity, final AEPartLocation side, final IFacadePart facade )
{
if( tileEntity instanceof IPartHost )
{
final IPartHost ph = (IPartHost) tileEntity;
final IFacadePart fp = ph.getFacadeContainer().getFacade( side );
return fp == null || ( fp.isTransparent() != facade.isTransparent() );
}
return true;
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
this.getBoxes( bch, null );
}
@Override
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( IPartHost host, BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline, IBlockState state, EnumFacing side, long rand )
{
List<BakedQuad> elements = new ArrayList();
elements.addAll( rotatingPipeline.pipe( ModelsCache.INSTANCE.getOrLoadBakedModel( new ResourceLocation( AppEng.MOD_ID, "part/cable_facade" ) ).getQuads( state, side, rand ), null, state, getSide().getFacing(), rand ) );
ItemStack titem = getTexture();
if( titem != null && titem.getItem() != null && Block.getBlockFromItem( titem.getItem() ) != null )
{
Block tblock = Block.getBlockFromItem( titem.getItem() );
IBlockState tstate = tblock.getStateFromMeta( titem.getItem().getMetadata( titem.getItemDamage() ) );
Vec3i s = getSide().getFacing().getDirectionVec();
Vector3f scale = new Vector3f( s.getX() == 0 ? 0.9999f : 0.125f, s.getY() == 0 ? 0.9999f : 0.125f, s.getZ() == 0 ? 0.9999f : 0.125f );
Vector3f trans = new Vector3f( s.getX() * 3.5f, s.getY() * 3.5f, s.getZ() * 3.5f );
elements.addAll( new BakingPipeline( new ParentQuads(), TypeTransformer.quads2vecs, new MatVecApplicator( TRSRTransformation.toVecmath( new Matrix4f().scale( scale ).translate( trans ) ), true ), new StatePosRecolorator( host.getTile().getWorld(), host.getLocation().getPos(), tstate ), TypeTransformer.vecs2quads ).pipe( new ArrayList<>(), Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState( tstate ), tstate, side, rand ) );
}
return elements;
}
}

View File

@ -46,7 +46,6 @@ import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.implementations.items.IItemGroup;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHelper;
import appeng.api.parts.IPartItem;
import appeng.api.util.AEColor;
import appeng.core.AEConfig;
@ -67,10 +66,8 @@ public final class ItemMultiPart extends AEBaseItem implements IPartItem, IItemG
public static ItemMultiPart instance;
private final Map<Integer, PartTypeWithVariant> registered;
public ItemMultiPart( final IPartHelper partHelper )
public ItemMultiPart()
{
Preconditions.checkNotNull( partHelper );
this.registered = new HashMap<>( INITIAL_REGISTERED_CAPACITY );
this.setHasSubtypes( true );

View File

@ -1,25 +1,35 @@
package appeng.items.parts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.api.util.AEColor;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
import appeng.client.render.StaticItemColor;
import appeng.core.AppEng;
import appeng.core.features.registries.PartModels;
import appeng.parts.automation.PlaneConnections;
import appeng.parts.automation.PlaneModel;
public class ItemMultipartRendering extends ItemRenderingCustomizer
{
private final PartModels partModels;
private final ItemMultiPart item;
public ItemMultipartRendering( ItemMultiPart item )
public ItemMultipartRendering( PartModels partModels, ItemMultiPart item )
{
this.partModels = partModels;
this.item = item;
}
@ -35,6 +45,52 @@ public class ItemMultipartRendering extends ItemRenderingCustomizer
rendering.variants( Arrays.stream( PartType.values() )
.flatMap( part -> part.getItemModels().stream() )
.collect( Collectors.toList() ) );
// TODO All of this has to go somewhere else! (I.e. when the part is registered)
// Register the built-in models for annihilation planes
ResourceLocation annihilationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/annihilation_plane" );
ResourceLocation annihilationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/annihilation_plane_on" );
ResourceLocation identityAnnihilationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/identity_annihilation_plane" );
ResourceLocation identityAnnihilationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/identity_annihilation_plane_on" );
ResourceLocation formationPlaneTexture = new ResourceLocation( AppEng.MOD_ID, "items/part/formation_plane" );
ResourceLocation formationPlaneOnTexture = new ResourceLocation( AppEng.MOD_ID, "parts/formation_plane_on" );
ResourceLocation sidesTexture = new ResourceLocation( AppEng.MOD_ID, "parts/plane_sides" );
ResourceLocation backTexture = new ResourceLocation( AppEng.MOD_ID, "parts/transition_plane_back" );
List<String> modelNames = new ArrayList<>();
for( PlaneConnections connection : PlaneConnections.PERMUTATIONS )
{
PlaneModel model = new PlaneModel( annihilationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/annihilation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/annihilation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel( annihilationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/annihilation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/annihilation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel( identityAnnihilationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/identity_annihilation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/identity_annihilation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel( identityAnnihilationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/identity_annihilation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/identity_annihilation_plane_on_" + connection.getFilenameSuffix() );
model = new PlaneModel( formationPlaneTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/formation_plane_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/formation_plane_" + connection.getFilenameSuffix() );
model = new PlaneModel( formationPlaneOnTexture, sidesTexture, backTexture, connection );
rendering.builtInModel( "models/part/formation_plane_on_" + connection.getFilenameSuffix(), model );
modelNames.add( "part/formation_plane_on_" + connection.getFilenameSuffix() );
}
List<ResourceLocation> partResourceLocs = modelNames.stream()
.map( name -> new ResourceLocation( AppEng.MOD_ID, name ) )
.collect( Collectors.toList() );
partModels.registerModels( partResourceLocs );
}
private ModelResourceLocation getItemMeshDefinition( ItemStack is )

View File

@ -0,0 +1,21 @@
package appeng.items.parts;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation is used to mark static fields or static methods that return/contain models used
* for a part. They are automatically registered as part of the part item registration.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( {
ElementType.FIELD,
ElementType.METHOD
} )
public @interface PartModels
{
}

View File

@ -20,9 +20,16 @@ package appeng.items.parts;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -34,6 +41,7 @@ import net.minecraft.util.ResourceLocation;
import appeng.api.parts.IPart;
import appeng.api.util.AEColor;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
@ -213,6 +221,7 @@ public enum PartType
private final Class<? extends IPart> myPart;
private final GuiText extraName;
private final List<ModelResourceLocation> itemModels;
private final Set<ResourceLocation> models;
private Constructor<? extends IPart> constructor;
PartType( final int baseMetaValue, final String name, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c )
@ -229,6 +238,14 @@ public enum PartType
this.myPart = c;
this.extraName = en;
this.itemModels = createItemModels( name );
if( c != null )
{
this.models = new HashSet<>( createModels( c ) );
}
else
{
this.models = Collections.emptySet();
}
}
protected List<ModelResourceLocation> createItemModels( String baseName )
@ -295,5 +312,125 @@ public enum PartType
{
return itemModels;
}
public Set<ResourceLocation> getModels()
{
return models;
}
private List<ResourceLocation> createModels( Class<?> clazz )
{
List<ResourceLocation> locations = new ArrayList<>( );
// Check all static fields for used models
Field[] fields = clazz.getDeclaredFields();
for( Field field : fields )
{
if( field.getAnnotation( PartModels.class ) == null )
{
continue;
}
if( !Modifier.isStatic( field.getModifiers() ) )
{
AELog.error( "The @PartModels annotation can only be used on static fields or methods. Was seen on: " + field );
continue;
}
Object value;
try
{
field.setAccessible( true );
value = field.get( null );
}
catch( IllegalAccessException e )
{
AELog.error( e, "Cannot access field annotated with @PartModels: " + field );
continue;
}
convertAndAddLocation( field, value, locations );
}
// Check all static methods for the annotation
for( Method method : clazz.getDeclaredMethods() )
{
if( method.getAnnotation( PartModels.class ) == null )
{
continue;
}
if( !Modifier.isStatic( method.getModifiers() ) )
{
AELog.error( "The @PartModels annotation can only be used on static fields or methods. Was seen on: " + method );
continue;
}
// Check for parameter count
if( method.getParameters().length != 0 )
{
AELog.error( "The @PartModels annotation can only be used on static methods without parameters. Was seen on: " + method );
continue;
}
// Make sure we can handle the return type
Class<?> returnType = method.getReturnType();
if( !ResourceLocation.class.isAssignableFrom( returnType ) && !Collection.class.isAssignableFrom( returnType ) )
{
AELog.error( "The @PartModels annotation can only be used on static methods that return a ResourceLocation or Collection of "
+ "ResourceLocations. Was seen on: " + method );
continue;
}
Object value = null;
try
{
method.setAccessible( true );
value = method.invoke( null );
}
catch( IllegalAccessException | InvocationTargetException e )
{
AELog.error( e, "Failed to invoke the @PartModels annotated method " + method );
continue;
}
convertAndAddLocation( method, value, locations );
}
if( clazz.getSuperclass() != null )
{
locations.addAll( createModels( clazz.getSuperclass() ) );
}
return locations;
}
private void convertAndAddLocation( Object source, Object value, List<ResourceLocation> locations )
{
if( value == null )
{
return;
}
if( value instanceof ResourceLocation )
{
locations.add( (ResourceLocation) value );
}
else if( value instanceof Collection )
{
// Check that each object is a ResourceLocation
Collection values = (Collection) value;
for( Object candidate : values )
{
if ( !( candidate instanceof ResourceLocation )) {
AELog.error( "List of locations obtained from {} contains a non resource location: {}", source, candidate );
continue;
}
locations.add( (ResourceLocation) candidate );
}
}
}
}

View File

@ -25,18 +25,12 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -55,7 +49,6 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.client.BakingPipeline;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IDefinitions;
import appeng.api.implementations.IUpgradeableHost;
@ -73,7 +66,6 @@ import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.client.render.model.ModelsCache;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.IPriorityHost;
import appeng.items.parts.ItemMultiPart;
@ -89,35 +81,6 @@ import appeng.util.SettingsFrom;
public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject
{
private static final Pattern PROPERTY_PATTERN = Pattern.compile( "\\$\\{([\\p{Alnum}_\\-\\.]+)\\}" );
public static final ResourceLocation replaceProperties( ResourceLocation location, ImmutableMap<String, String> properties )
{
Matcher m = PROPERTY_PATTERN.matcher( location.getResourcePath() );
StringBuffer buffer = new StringBuffer();
while( m.find() )
{
m.appendReplacement( buffer, properties.get( m.group( 1 ) ) );
}
m.appendTail( buffer );
return new ResourceLocation( location.getResourceDomain(), buffer.toString() );
}
protected static final Function<ResourceLocation, TextureAtlasSprite> propertyTextureGetter( ImmutableMap<String, String> properties )
{
return location -> ModelsCache.DEFAULTTEXTUREGETTER.apply( replaceProperties( location, properties ) );
}
protected static final Function<ResourceLocation, TextureAtlasSprite> propertyTextureGetter( ImmutableMap.Builder<String, String> properties )
{
return propertyTextureGetter( properties.build() );
}
protected static final ResourceLocation withProperties( ResourceLocation location, ImmutableMap.Builder<String, String> properties )
{
return new ResourceLocation( location.getResourceDomain(), location.getResourcePath() + properties.build().toString() );
}
private final AENetworkProxy proxy;
private final ItemStack is;
private TileEntity tile = null;
@ -567,13 +530,6 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
return false;
}
@Override
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline, IBlockState state, EnumFacing side, long rand )
{
return rotatingPipeline.pipe( ModelsCache.INSTANCE.getOrLoadModel( withProperties( getDefaultModelLocation(), propertiesForModel( getSide().getFacing() ) ), getDefaultModelLocation(), propertyTextureGetter( propertiesForModel( getSide().getFacing() ) ) ).getQuads( state, side, rand ), null, state, getSide().getFacing(), rand );
}
protected ImmutableMap.Builder<String, String> propertiesForModel( EnumFacing facing )
{
return ImmutableMap.<String, String>builder().put( "color", getColor().name() );

View File

@ -25,7 +25,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
import io.netty.buffer.ByteBuf;
@ -63,6 +62,8 @@ import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.client.render.cablebus.CableBusRenderState;
import appeng.client.render.cablebus.CableCoreType;
import appeng.core.AELog;
import appeng.facade.FacadeContainer;
import appeng.helpers.AEMultiTile;
@ -70,6 +71,7 @@ import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.ICLApi;
import appeng.me.GridConnection;
import appeng.parts.networking.PartCable;
import appeng.util.Platform;
@ -1148,4 +1150,95 @@ public class CableBusContainer extends CableBusStorage implements AEMultiTile, I
{
this.requiresDynamicRender = requiresDynamicRender;
}
@Override
public CableBusRenderState getRenderState()
{
// TODO: Inspect whether this is a problem. PartCable is the only implementor of IPartCable, which is not part of the public API
PartCable cable = (PartCable) getCenter();
CableBusRenderState renderState = new CableBusRenderState();
if( cable != null )
{
renderState.setCableColor( cable.getCableColor() );
renderState.setCableType( cable.getCableConnectionType() );
renderState.setCoreType( cable.getCableConnectionType().getCoreType() );
// Check each outgoing connection for the desired characteristics
for( EnumFacing facing : EnumFacing.values() )
{
// Is there a connection?
if( !cable.isConnected( facing ) )
{
continue;
}
// If there is one, check out which type it has, but default to this cable's type
AECableType connectionType = cable.getCableConnectionType();
// Only use the incoming cable-type of the adjacent block, if it's not a cable bus itself
// Dense cables however also respect the adjacent cable-type since their outgoing connection
// point would look too big for other cable types
BlockPos adjacentPos = this.getTile().getPos().offset( facing );
TileEntity adjacentTe = this.getTile().getWorld().getTileEntity( adjacentPos );
if( adjacentTe instanceof IGridHost )
{
if( !( adjacentTe instanceof IPartHost ) || cable.getCableConnectionType() == AECableType.DENSE )
{
IGridHost gridHost = (IGridHost) adjacentTe;
connectionType = gridHost.getCableConnectionType( AEPartLocation.fromFacing( facing.getOpposite() ) );
}
}
// Check if the adjacent TE is a cable bus or not
if( adjacentTe instanceof IPartHost )
{
renderState.getCableBusAdjacent().add( facing );
}
renderState.getConnectionTypes().put( facing, connectionType );
}
// Collect the number of channels used per side
// We have to do this even for non-smart cables since a glass cable can display a connection as smart if the adjacent tile requires it
for( EnumFacing facing : EnumFacing.values() )
{
int channels = cable.getChannelsOnSide( facing );
renderState.getChannelsOnSide().put( facing, channels );
}
}
for( EnumFacing facing : EnumFacing.values() )
{
IPart part = getPart( facing );
if( part == null )
{
continue;
}
if( part instanceof IGridHost )
{
// Some attachments want a thicker cable than glass, account for that
IGridHost gridHost = (IGridHost) part;
AECableType desiredType = gridHost.getCableConnectionType( AEPartLocation.INTERNAL );
if( renderState.getCoreType() == CableCoreType.GLASS && ( desiredType == AECableType.SMART || desiredType == AECableType.COVERED ) )
{
renderState.setCoreType( CableCoreType.COVERED );
}
int length = (int) part.getCableConnectionLength( null );
if( length > 0 && length <= 8 )
{
renderState.getAttachmentConnections().put( facing, length );
}
}
renderState.getAttachments().put( facing, part.getStaticModels() );
}
return renderState;
}
}

View File

@ -35,6 +35,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEColor;
import appeng.client.render.cablebus.CableBusRenderState;
public interface ICableBusContainer
@ -66,4 +67,7 @@ public interface ICableBusContainer
void randomDisplayTick( World world, BlockPos pos, Random r );
int getLightValue();
CableBusRenderState getRenderState();
}

View File

@ -33,6 +33,7 @@ import net.minecraft.world.World;
import appeng.api.parts.SelectedPart;
import appeng.api.util.AEColor;
import appeng.client.render.cablebus.CableBusRenderState;
public class NullCableBusContainer implements ICableBusContainer
@ -115,4 +116,11 @@ public class NullCableBusContainer implements ICableBusContainer
{
return 0;
}
@Override
public CableBusRenderState getRenderState()
{
return new CableBusRenderState();
}
}

View File

@ -31,6 +31,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -58,6 +59,7 @@ import appeng.api.util.AEPartLocation;
import appeng.core.settings.TickRates;
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.hooks.TickHandler;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.parts.PartBasicState;
import appeng.server.ServerHelper;
@ -69,6 +71,14 @@ import appeng.util.item.AEItemStack;
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, IWorldCallable<TickRateModulation>
{
private static final PlaneModels MODELS = new PlaneModels( "part/annihilation_plane_", "part/annihilation_plane_on_" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private final BaseActionSource mySrc = new MachineSource( this );
private boolean isAccepting = true;
private boolean breaking = false;
@ -128,6 +138,78 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
}
/**
* @return An object describing which adjacent planes this plane connects to visually.
*/
public PlaneConnections getConnections()
{
final EnumFacing facingRight, facingUp;
AEPartLocation location = getSide();
switch( location )
{
case UP:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.NORTH;
break;
case DOWN:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.NORTH;
break;
case NORTH:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.UP;
break;
case SOUTH:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.UP;
break;
case WEST:
facingRight = EnumFacing.SOUTH;
facingUp = EnumFacing.UP;
break;
case EAST:
facingRight = EnumFacing.NORTH;
facingUp = EnumFacing.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of( false, false, false, false );
}
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
{
left = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
{
right = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
{
down = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
{
up = true;
}
}
return PlaneConnections.of( up, right, down, left );
}
@Override
public void onNeighborChanged()
{
@ -235,6 +317,7 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
* Stores an {@link ItemStack} inside the network.
*
* @param item {@link ItemStack} to store
*
* @return the leftover items, which could not be stored inside the network
*/
private IAEItemStack storeItemStack( final ItemStack item )
@ -265,6 +348,7 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
*
* @param entityItem the entity to update or destroy
* @param overflow the leftover {@link IAEItemStack}
*
* @return true, if the entity was changed otherwise false.
*/
private boolean handleOverflow( final EntityItem entityItem, final IAEItemStack overflow )
@ -496,4 +580,11 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
this.spawnOverflow( overflow );
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( getConnections(), isPowered(), isActive() );
}
}

View File

@ -19,6 +19,8 @@
package appeng.parts.automation;
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -26,6 +28,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.config.Actionable;
@ -51,10 +54,12 @@ import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.core.sync.GuiBridge;
import appeng.helpers.MultiCraftingTracker;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
@ -63,6 +68,24 @@ import appeng.util.item.AEItemStack;
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
@PartModels
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/export_bus_off" )
);
@PartModels
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/export_bus_on" )
);
@PartModels
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/export_bus_has_channel" )
);
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker( this, 9 );
private final BaseActionSource mySrc;
private long itemToSend = 1;
@ -337,4 +360,22 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
this.nextSlot = ( this.nextSlot + x ) % this.availableSlots();
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -37,6 +37,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@ -73,6 +74,7 @@ import appeng.api.util.IConfigManager;
import appeng.core.AEConfig;
import appeng.core.sync.GuiBridge;
import appeng.helpers.IPriorityHost;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.inventory.AppEngInternalAEInventory;
@ -84,6 +86,15 @@ import appeng.util.prioitylist.PrecisePriorityList;
public class PartFormationPlane extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<IAEItemStack>
{
private static final PlaneModels MODELS = new PlaneModels( "part/formation_plane_", "part/formation_plane_on_" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private final MEInventoryHandler myHandler = new MEInventoryHandler( this, StorageChannel.ITEMS );
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private int priority = 0;
@ -262,6 +273,79 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
}
// TODO: Consolidate this with the impl in PartAnnihilationPlane
/**
* @return An object describing which adjacent planes this plane connects to visually.
*/
public PlaneConnections getConnections()
{
final EnumFacing facingRight, facingUp;
AEPartLocation location = getSide();
switch( location )
{
case UP:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.NORTH;
break;
case DOWN:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.NORTH;
break;
case NORTH:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.UP;
break;
case SOUTH:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.UP;
break;
case WEST:
facingRight = EnumFacing.SOUTH;
facingUp = EnumFacing.UP;
break;
case EAST:
facingRight = EnumFacing.NORTH;
facingUp = EnumFacing.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of( false, false, false, false );
}
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
{
left = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
{
right = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
{
down = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
{
up = true;
}
}
return PlaneConnections.of( up, right, down, left );
}
@Override
public void onNeighborChanged()
{
@ -525,4 +609,11 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
{
// nope!
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( getConnections(), isPowered(), isActive() );
}
}

View File

@ -26,6 +26,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
@ -34,11 +35,20 @@ import net.minecraftforge.common.util.FakePlayerFactory;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.util.AEPartLocation;
import appeng.items.parts.PartModels;
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane
{
private static final PlaneModels MODELS = new PlaneModels( "part/identity_annihilation_plane_", "part/identity_annihilation_plane_on_" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private static final float SILK_TOUCH_FACTOR = 16;
public PartIdentityAnnihilationPlane( final ItemStack is )
@ -93,4 +103,11 @@ public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane
return super.obtainBlockDrops( w, pos );
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( getConnections(), isPowered(), isActive() );
}
}

View File

@ -19,9 +19,14 @@
package appeng.parts.automation;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.AEApi;
@ -43,9 +48,11 @@ import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
@ -55,6 +62,24 @@ import appeng.util.item.AEItemStack;
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/import_bus_base" );
@PartModels
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/import_bus_off" )
);
@PartModels
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/import_bus_on" )
);
@PartModels
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/import_bus_has_channel" )
);
private final BaseActionSource source;
private IMEInventory<IAEItemStack> destination = null;
private IAEItemStack lastItemChecked = null;
@ -294,4 +319,22 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
{
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -20,8 +20,11 @@ package appeng.parts.automation;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
@ -30,6 +33,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@ -67,8 +71,10 @@ import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
@ -78,6 +84,24 @@ import appeng.util.Platform;
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
{
@PartModels
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_off" );
@PartModels
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_on" );
@PartModels
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_off" );
@PartModels
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_on" );
@PartModels
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_has_channel" );
public static final List<ResourceLocation> MODEL_OFF_OFF = ImmutableList.of( MODEL_BASE_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODEL_OFF_ON = ImmutableList.of( MODEL_BASE_OFF, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODEL_OFF_HAS_CHANNEL = ImmutableList.of( MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL );
public static final List<ResourceLocation> MODEL_ON_OFF = ImmutableList.of( MODEL_BASE_ON, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODEL_ON_ON = ImmutableList.of( MODEL_BASE_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODEL_ON_HAS_CHANNEL = ImmutableList.of( MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL );
private static final int FLAG_ON = 4;
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 1 );
@ -142,7 +166,8 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
}
private boolean isLevelEmitterOn()
// TODO: Make private again
public boolean isLevelEmitterOn()
{
if( Platform.isClient() )
{
@ -534,4 +559,21 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( isActive() && isPowered() )
{
return isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
}
else if( isPowered() )
{
return isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
}
else
{
return isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
}
}
}

View File

@ -0,0 +1,104 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
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 appeng.client.render.cablebus.CubeBuilder;
/**
* Built-in model for annihilation planes that supports connected textures.
*/
public class PlaneBakedModel implements IBakedModel
{
private final TextureAtlasSprite frontTexture;
private final List<BakedQuad> quads;
PlaneBakedModel( VertexFormat format, TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture,
PlaneConnections connections )
{
this.frontTexture = frontTexture;
List<BakedQuad> quads = new ArrayList<>( 4 * 6 );
CubeBuilder builder = new CubeBuilder( format, quads );
builder.setTextures( sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture );
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
// The X-axis points left
int minX = connections.isRight() ? 0 : 1;
int maxX = connections.isLeft() ? 16 : 15;
int minY = connections.isDown() ? 0 : 1;
int maxY = connections.isUp() ? 16 : 15;
builder.addCube( minX, minY, 0, maxX, maxY, 1 );
this.quads = ImmutableList.copyOf( quads );
}
@Override
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
{
if( side == null )
{
return quads;
}
else
{
return Collections.emptyList();
}
}
@Override
public boolean isAmbientOcclusion()
{
return false;
}
@Override
public boolean isGui3d()
{
return false;
}
@Override
public boolean isBuiltInRenderer()
{
return false;
}
@Override
public TextureAtlasSprite getParticleTexture()
{
return frontTexture;
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public ItemOverrideList getOverrides()
{
return ItemOverrideList.NONE;
}
}

View File

@ -0,0 +1,121 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Strings;
/**
* Models in which directions - looking at the front face - a plane (annihilation, formation, etc.) is connected to other planes of the same type.
*/
public final class PlaneConnections
{
private final boolean up;
private final boolean right;
private final boolean down;
private final boolean left;
private static final int BITMASK_UP = 8;
private static final int BITMASK_RIGHT = 4;
private static final int BITMASK_DOWN = 2;
private static final int BITMASK_LEFT = 1;
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
private static List<PlaneConnections> generatePermutations()
{
List<PlaneConnections> connections = new ArrayList<>( 16 );
for( int i = 0; i < 16; i++ )
{
boolean up = ( i & BITMASK_UP ) != 0;
boolean right = ( i & BITMASK_RIGHT ) != 0;
boolean down = ( i & BITMASK_DOWN ) != 0;
boolean left = ( i & BITMASK_LEFT ) != 0;
connections.add( new PlaneConnections( up, right, down, left ) );
}
return connections;
}
private PlaneConnections( boolean up, boolean right, boolean down, boolean left )
{
this.up = up;
this.right = right;
this.down = down;
this.left = left;
}
public static PlaneConnections of( boolean up, boolean right, boolean down, boolean left )
{
return PERMUTATIONS.get( getIndex( up, right, down, left ) );
}
public boolean isUp()
{
return up;
}
public boolean isRight()
{
return right;
}
public boolean isDown()
{
return down;
}
public boolean isLeft()
{
return left;
}
// The combination of connections expressed as a number ranging from [0,15]
public int getIndex()
{
return getIndex( up, right, down, left );
}
private static int getIndex( boolean up, boolean right, boolean down, boolean left )
{
return ( up ? BITMASK_UP : 0 ) + ( right ? BITMASK_RIGHT : 0 ) + ( left ? BITMASK_LEFT : 0 ) + ( down ? BITMASK_DOWN : 0 );
}
// Returns a suffix that expresses the connection states as a string
public String getFilenameSuffix()
{
String suffix = Integer.toBinaryString( getIndex() );
return Strings.padStart(suffix, 4, '0');
}
@Override
public boolean equals( Object o )
{
if( this == o )
{
return true;
}
if( o == null || getClass() != o.getClass() )
{
return false;
}
PlaneConnections that = (PlaneConnections) o;
return up == that.up && right == that.right && down == that.down && left == that.left;
}
@Override
public int hashCode()
{
int result = ( up ? 1 : 0 );
result = 31 * result + ( right ? 1 : 0 );
result = 31 * result + ( down ? 1 : 0 );
result = 31 * result + ( left ? 1 : 0 );
return result;
}
}

View File

@ -0,0 +1,66 @@
package appeng.parts.automation;
import java.util.Collection;
import java.util.Collections;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
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;
/**
* Built-in model for annihilation planes that supports connected textures.
*/
public class PlaneModel implements IModel
{
private final ResourceLocation frontTexture;
private final ResourceLocation sidesTexture;
private final ResourceLocation backTexture;
private final PlaneConnections connections;
public PlaneModel( ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture, PlaneConnections connections )
{
this.frontTexture = frontTexture;
this.sidesTexture = sidesTexture;
this.backTexture = backTexture;
this.connections = connections;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptyList();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return Lists.newArrayList( frontTexture, sidesTexture, backTexture );
}
@Override
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
TextureAtlasSprite frontSprite = bakedTextureGetter.apply( frontTexture );
TextureAtlasSprite sidesSprite = bakedTextureGetter.apply( sidesTexture );
TextureAtlasSprite backSprite = bakedTextureGetter.apply( backTexture );
return new PlaneBakedModel( format, frontSprite, sidesSprite, backSprite, connections );
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
}

View File

@ -0,0 +1,79 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
/**
* Contains a mapping from a Plane's connections to the models to use for that state.
*/
class PlaneModels
{
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_off" );
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_on" );
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_has_channel" );
private final Map<PlaneConnections, List<ResourceLocation>> modelsOff;
private final Map<PlaneConnections, List<ResourceLocation>> modelsOn;
private final Map<PlaneConnections, List<ResourceLocation>> modelsHasChannel;
public PlaneModels( String prefixOff, String prefixOn )
{
Map<PlaneConnections, List<ResourceLocation>> modelsOff = new HashMap<>();
Map<PlaneConnections, List<ResourceLocation>> modelsOn = new HashMap<>();
Map<PlaneConnections, List<ResourceLocation>> modelsHasChannel = new HashMap<>();
for( PlaneConnections permutation : PlaneConnections.PERMUTATIONS )
{
ResourceLocation planeOff = new ResourceLocation( AppEng.MOD_ID, prefixOff + permutation.getFilenameSuffix() );
ResourceLocation planeOn = new ResourceLocation( AppEng.MOD_ID, prefixOn + permutation.getFilenameSuffix() );
modelsOff.put( permutation, ImmutableList.of( MODEL_CHASSIS_OFF, planeOff ) );
modelsOn.put( permutation, ImmutableList.of( MODEL_CHASSIS_ON, planeOff ) );
modelsHasChannel.put( permutation, ImmutableList.of( MODEL_CHASSIS_HAS_CHANNEL, planeOn ) );
}
this.modelsOff = ImmutableMap.copyOf( modelsOff );
this.modelsOn = ImmutableMap.copyOf( modelsOn );
this.modelsHasChannel = ImmutableMap.copyOf( modelsHasChannel );
}
public List<ResourceLocation> getModel( PlaneConnections connections, boolean hasPower, boolean hasChannel )
{
if( hasPower && hasChannel )
{
return modelsHasChannel.get( connections );
}
else if( hasPower )
{
return modelsOn.get( connections );
}
else
{
return modelsOff.get( connections );
}
}
public List<ResourceLocation> getModels()
{
List<ResourceLocation> result = new ArrayList<>();
modelsOff.values().forEach( result::addAll );
modelsOn.values().forEach( result::addAll );
modelsHasChannel.values().forEach( result::addAll );
return result;
}
}

View File

@ -20,30 +20,22 @@ package appeng.parts.misc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.client.BakingPipeline;
import appeng.api.networking.IGridNode;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPart;
@ -52,8 +44,6 @@ import appeng.api.parts.IPartHost;
import appeng.api.parts.PartItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.client.render.model.ModelsCache;
import appeng.core.AppEng;
public class PartCableAnchor implements IPart
@ -238,11 +228,4 @@ public class PartCableAnchor implements IPart
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
}
@Override
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( BakingPipeline<BakedQuad, BakedQuad> rotatingPipeline, IBlockState state, EnumFacing side, long rand )
{
return rotatingPipeline.pipe( ModelsCache.INSTANCE.getOrLoadBakedModel( new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor" ) ).getQuads( state, side, rand ), null, state, mySide.getFacing(), rand );
}
}

View File

@ -22,6 +22,7 @@ package appeng.parts.misc;
import java.util.EnumSet;
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
@ -33,6 +34,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
@ -57,11 +59,13 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.PartBasicState;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
@ -72,6 +76,23 @@ import appeng.util.inv.IInventoryDestination;
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, ISidedInventory, IAEAppEngInventory, ITileStorageMonitorable, IPriorityHost
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/interface_base" );
@PartModels
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/interface_off" )
);
@PartModels
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/interface_on" )
);
@PartModels
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/interface_has_channel" )
);
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
@Reflected
@ -405,4 +426,22 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
{
return null;
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -19,13 +19,27 @@
package appeng.parts.misc;
import net.minecraft.item.ItemStack;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
public class PartInvertedToggleBus extends PartToggleBus
{
@PartModels
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/inverted_toggle_bus_base" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(MODEL_BASE, MODEL_STATUS_OFF);
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(MODEL_BASE, MODEL_STATUS_ON);
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
@Reflected
public PartInvertedToggleBus( final ItemStack is )
{
@ -41,4 +55,22 @@ public class PartInvertedToggleBus extends PartToggleBus
{
return !super.getIntention();
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( hasRedstoneFlag() && isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( hasRedstoneFlag() && isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -23,12 +23,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.AEApi;
@ -64,12 +67,14 @@ import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.core.stats.Achievements;
import appeng.core.sync.GuiBridge;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.me.storage.MEMonitorIInventory;
@ -88,6 +93,24 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
* IPipeConnection
*/, IPriorityHost
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_base" );
@PartModels
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_off" )
);
@PartModels
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_on" )
);
@PartModels
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(
MODEL_BASE,
new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_has_channel" )
);
private final BaseActionSource mySrc;
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private int priority = 0;
@ -530,4 +553,22 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
{
// nope!
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -23,16 +23,14 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.lwjgl.opengl.GL11;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.util.ResourceLocation;
import appeng.api.AEApi;
import appeng.api.exceptions.FailedConnection;
@ -42,7 +40,9 @@ import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.PartBasicState;
import appeng.util.Platform;
@ -50,6 +50,20 @@ import appeng.util.Platform;
public class PartToggleBus extends PartBasicState
{
@PartModels
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_base" );
@PartModels
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_off" );
@PartModels
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_on" );
@PartModels
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_has_channel" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of(MODEL_BASE, MODEL_STATUS_OFF);
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of(MODEL_BASE, MODEL_STATUS_ON);
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
private static final int REDSTONE_FLAG = 4;
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
private IGridConnection connection;
@ -72,6 +86,10 @@ public class PartToggleBus extends PartBasicState
return cf | ( this.getIntention() ? REDSTONE_FLAG : 0 );
}
public boolean hasRedstoneFlag() {
return (getClientFlags() & REDSTONE_FLAG) == REDSTONE_FLAG;
}
protected boolean getIntention()
{
return this.getHost().hasRedstone( this.getSide() );
@ -202,4 +220,21 @@ public class PartToggleBus extends PartBasicState
{
return this.outerProxy;
}
@Override
public List<ResourceLocation> getStaticModels()
{
if( hasRedstoneFlag() && isActive() && isPowered() )
{
return MODELS_HAS_CHANNEL;
}
else if( hasRedstoneFlag() && isPowered() )
{
return MODELS_ON;
}
else
{
return MODELS_OFF;
}
}
}

View File

@ -20,31 +20,18 @@ package appeng.parts.networking;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.ImmutableSet;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.AEApi;
import appeng.api.client.BakingPipeline;
import appeng.api.config.SecurityPermissions;
import appeng.api.definitions.IParts;
import appeng.api.implementations.parts.IPartCable;
@ -53,7 +40,6 @@ import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.parts.BusSupport;
import appeng.api.parts.ICustomCableConnection;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
@ -61,10 +47,6 @@ import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IReadOnlyCollection;
import appeng.client.render.model.ModelsCache;
import appeng.client.render.model.pipeline.FacingQuadRotator;
import appeng.client.render.model.pipeline.MatVecApplicator;
import appeng.client.render.model.pipeline.TypeTransformer;
import appeng.items.parts.ItemMultiPart;
import appeng.me.GridAccessException;
import appeng.parts.AEBasePart;
@ -401,86 +383,16 @@ public class PartCable extends AEBasePart implements IPartCable
return !myC.equals( this.getConnections() ) || wasPowered != this.powered || channelsChanged;
}
@Override
@SideOnly( Side.CLIENT )
public List<BakedQuad> getOrBakeQuads( BakingPipeline rotatingPipeline, IBlockState state, EnumFacing side, long rand )
{
List<BakedQuad> elements = new ArrayList<>();
if( isStraight( getHost(), connections ) )
{
EnumFacing facing = getConnections().contains( AEPartLocation.DOWN ) ? EnumFacing.DOWN : getConnections().contains( AEPartLocation.NORTH ) ? EnumFacing.NORTH : getConnections().contains( AEPartLocation.EAST ) ? EnumFacing.EAST : EnumFacing.NORTH;
elements.addAll( rotatingPipeline.pipe( ModelsCache.INSTANCE.getOrLoadModel( withProperties( getCableConnectionType().getStraightModel(), propertiesForModel( facing ) ), getCableConnectionType().getStraightModel(), propertyTextureGetter( propertiesForModel( facing ) ) ).getQuads( state, side, rand ), null, state, connections.contains( AEPartLocation.DOWN ) ? EnumFacing.DOWN : connections.contains( AEPartLocation.NORTH ) ? EnumFacing.NORTH : connections.contains( AEPartLocation.EAST ) ? EnumFacing.EAST : EnumFacing.NORTH, rand ) );
}
else
{
elements.addAll( ModelsCache.INSTANCE.getOrLoadModel( withProperties( getCableConnectionType().getModel(), propertiesForModel( null ) ), getCableConnectionType().getModel(), propertyTextureGetter( propertiesForModel( null ) ) ).getQuads( state, side, rand ) );
for( EnumFacing facing : EnumFacing.values() )
{
if( isConnected( facing ) || getHost().getPart( facing ) != null )
{
float f = 4;
if( getHost().getPart( facing ) != null )
{
f = getHost().getPart( facing ).getCableConnectionLength( this.getCableConnectionType() );
}
else
{
TileEntity to = getHost().getTile().getWorld().getTileEntity( getHost().getTile().getPos().offset( facing ) );
if( to instanceof ICustomCableConnection )
{
f = ( (ICustomCableConnection) to ).getCableConnectionLength( this.getCableConnectionType() );
}
}
if( f != -1 )
{
elements.addAll( new BakingPipeline( TypeTransformer.quads2vecs, new MatVecApplicator( TRSRTransformation.toVecmath( new Matrix4f().scale( new Vector3f( 1, 1, f / 4f ) ) ) ), new FacingQuadRotator( facing ), TypeTransformer.vecs2quads ).pipe( ModelsCache.INSTANCE.getOrLoadModel( withProperties( getCableConnectionType().getConnectionModel(), propertiesForModel( facing ) ), getCableConnectionType().getConnectionModel(), propertyTextureGetter( propertiesForModel( facing ) ) ).getQuads( state, side, rand ), null, state, facing, rand ) );
}
}
}
}
return elements;
}
/**
* A cable connection is considered straight, if there are exactly two connection points on opposite sides,
* and the cable has no attached busses.
*/
protected boolean isStraight( IPartHost host, final EnumSet<AEPartLocation> sides )
{
if (sides.size() != 2) {
return false;
}
Iterator<AEPartLocation> it = sides.iterator();
EnumFacing firstSide = it.next().getFacing();
EnumFacing secondSide = it.next().getFacing();
// Not on opposite sides
if (firstSide.getOpposite() != secondSide) {
return false;
}
// Check any other point for attachments
for( EnumFacing facing : EnumFacing.values() )
{
if( facing != firstSide && facing != secondSide )
{
// Check for an attached part here
if( host.getPart( facing ) != null )
{
return false;
}
}
}
return true;
}
int getChannelsOnSide( final int i )
{
return this.channelsOnSide[i];
}
public int getChannelsOnSide( EnumFacing side )
{
return this.channelsOnSide[side.ordinal()];
}
void setChannelsOnSide( final int i, final int channels )
{
this.channelsOnSide[i] = channels;

View File

@ -19,7 +19,9 @@
package appeng.parts.networking;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
@ -27,6 +29,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import appeng.api.config.Actionable;
import appeng.api.networking.GridFlags;
@ -37,6 +40,8 @@ import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.parts.AEBasePart;
@ -45,6 +50,9 @@ import appeng.parts.AEBasePart;
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
{
@PartModels
private static final List<ResourceLocation> MODELS = Collections.singletonList( new ResourceLocation( AppEng.MOD_ID, "part/quartz_fiber" ) );
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", this.getProxy().getMachineRepresentation(), true );
public PartQuartzFiber( final ItemStack is )
@ -210,4 +218,10 @@ public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
return demand;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS;
}
}

View File

@ -0,0 +1,60 @@
package appeng.parts.p2p;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
/**
* Helper for maintaining the models used for a variant of the P2P bus.
*/
class P2PModels
{
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off" );
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on" );
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel" );
private final List<ResourceLocation> modelsOff;
private final List<ResourceLocation> modelsOn;
private final List<ResourceLocation> modelsHasChannel;
public P2PModels( String frontModelPath )
{
ResourceLocation frontModel = new ResourceLocation( AppEng.MOD_ID, frontModelPath );
modelsOff = ImmutableList.of( MODEL_STATUS_OFF, frontModel );
modelsOn = ImmutableList.of( MODEL_STATUS_ON, frontModel );
modelsHasChannel = ImmutableList.of( MODEL_STATUS_HAS_CHANNEL, frontModel );
}
public List<ResourceLocation> getModel( boolean hasPower, boolean hasChannel )
{
if( hasPower && hasChannel )
{
return modelsHasChannel;
}
else if( hasPower )
{
return modelsOn;
}
else
{
return modelsOff;
}
}
public List<ResourceLocation> getModels() {
List<ResourceLocation> result = new ArrayList<>();
result.addAll( modelsOff );
result.addAll( modelsOn );
result.addAll( modelsHasChannel );
return result;
}
}

View File

@ -29,6 +29,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import appeng.api.networking.IGridNode;
@ -43,6 +44,7 @@ import appeng.core.settings.TickRates;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IBuildCraftTransport;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.tile.inventory.AppEngNullInventory;
@ -57,6 +59,14 @@ import appeng.util.inv.WrapperMCISidedInventory;
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPipeConnection, */ISidedInventory, IGridTickable
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_items" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private final LinkedList<IInventory> which = new LinkedList<IInventory>();
private int oldSize = 0;
private boolean requested;
@ -412,4 +422,11 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
// {
// return this.side == with && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
// }
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}

View File

@ -20,12 +20,14 @@ package appeng.parts.p2p;
import java.io.IOException;
import java.util.List;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import appeng.api.networking.IGridNode;
@ -35,12 +37,21 @@ import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.core.settings.TickRates;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_light" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private int lastValue = 0;
private float opacity = -1;
@ -213,4 +224,11 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
{
return 0.5f;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}

View File

@ -27,17 +27,27 @@ import java.util.Stack;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_liquids" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private static final ThreadLocal<Stack<PartP2PLiquids>> DEPTH = new ThreadLocal<Stack<PartP2PLiquids>>();
private static final FluidTankInfo[] ACTIVE_TANK = { new FluidTankInfo( null, 10000 ) };
private static final FluidTankInfo[] INACTIVE_TANK = { new FluidTankInfo( null, 0 ) };
@ -292,4 +302,11 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
}
return INACTIVE_TANK;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}

View File

@ -19,12 +19,15 @@
package appeng.parts.p2p;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -32,6 +35,7 @@ import appeng.api.networking.events.MENetworkBootingStatusChange;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.Platform;
@ -39,6 +43,14 @@ import appeng.util.Platform;
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_redstone" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private int power;
private boolean recursive = false;
@ -195,4 +207,11 @@ public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
// :P
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}

View File

@ -22,12 +22,14 @@ package appeng.parts.p2p;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import appeng.api.AEApi;
import appeng.api.exceptions.FailedConnection;
@ -42,6 +44,7 @@ import appeng.api.util.AEPartLocation;
import appeng.core.AELog;
import appeng.core.settings.TickRates;
import appeng.hooks.TickHandler;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.Connections;
import appeng.me.cache.helpers.TunnelConnection;
@ -51,6 +54,14 @@ import appeng.me.helpers.AENetworkProxy;
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_me" );
@PartModels
public static List<ResourceLocation> getModels()
{
return MODELS.getModels();
}
private final Connections connection = new Connections( this );
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
@ -246,4 +257,11 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
}
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}

View File

@ -20,6 +20,10 @@ package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;
/**
@ -36,6 +40,18 @@ import net.minecraft.item.ItemStack;
public abstract class AbstractPartDisplay extends AbstractPartReporting
{
// The base chassis of all display parts
@PartModels
protected static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/display_base" );
// Models that contain the status indicator light
@PartModels
protected static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/display_status_off" );
@PartModels
protected static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/display_status_on" );
@PartModels
protected static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/display_status_has_channel" );
public AbstractPartDisplay( final ItemStack is )
{
super( is, true );

View File

@ -20,22 +20,21 @@ package appeng.parts.reporting;
import java.io.IOException;
import java.util.List;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
@ -52,7 +51,6 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.client.ClientHelper;
import appeng.core.AELog;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.Reflected;
import appeng.me.GridAccessException;
@ -80,10 +78,6 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
private String lastHumanReadableText;
private boolean isLocked;
private IStackWatcher myWatcher;
@SideOnly( Side.CLIENT )
private boolean updateList;
@SideOnly( Side.CLIENT )
private Integer dspList;
@Reflected
public AbstractPartMonitor( final ItemStack is )
@ -151,8 +145,6 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
this.configuredItem = null;
}
this.updateList = true;
return needRedraw;
}
@ -246,34 +238,26 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
@Override
@SideOnly( Side.CLIENT )
protected void finalize() throws Throwable
public void renderDynamic( double x, double y, double z, float partialTicks, int destroyStage )
{
super.finalize();
if( this.dspList != null )
if( ( this.getClientFlags() & ( PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG ) ) != ( PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG ) )
{
GLAllocation.deleteDisplayLists( this.dspList );
return;
}
}
@Override
public boolean requireDynamicRender()
{
return true;
}
final IAEItemStack ais = (IAEItemStack) this.getDisplayed();
@Override
public IAEStack<?> getDisplayed()
{
return this.configuredItem;
}
if( ais == null )
{
return;
}
private void tesrRenderScreen( final VertexBuffer wr, final IAEItemStack ais )
{
// GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
GlStateManager.pushMatrix();
GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 );
final AEPartLocation d = this.getSide();
GL11.glTranslated( d.xOffset * 0.77, d.yOffset * 0.77, d.zOffset * 0.77 );
GL11.glTranslated( d.xOffset * 0.50, d.yOffset * 0.50, d.zOffset * 0.50 );
switch( d )
{
@ -312,46 +296,33 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
break;
}
try
{
final ItemStack sis = ais.getItemStack();
sis.stackSize = 1;
final int br = 16 << 20 | 16 << 4;
final int var11 = br % 65536;
final int var12 = br / 65536;
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11 * 0.8F, var12 * 0.8F );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
// RenderHelper.enableGUIStandardItemLighting();
ClientHelper.proxy.doRenderItem( sis, this.getTile().getWorld() );
}
catch( final Exception e )
{
AELog.debug( e );
}
finally
{
GL11.glEnable( GL11.GL_LIGHTING );
GL11.glEnable( GL12.GL_RESCALE_NORMAL );
}
GL11.glTranslatef( 0.0f, 0.14f, -0.24f );
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
ClientHelper.proxy.doRenderItem( ais.getItemStack() );
final long stackSize = ais.getStackSize();
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm( stackSize );
// Render the item count
final FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
final int width = fr.getStringWidth( renderedStackSize );
GL11.glTranslatef( -0.5f * width, 0.0f, -1.0f );
GL11.glTranslatef( 0.0f, 0.17f, 0 );
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
GL11.glTranslatef( -0.5f * width, 0.0f, 0.5f );
fr.drawString( renderedStackSize, 0, 0, 0 );
// GL11.glPopAttrib();
GlStateManager.popMatrix();
}
@Override
public boolean requireDynamicRender()
{
return true;
}
@Override
public IAEStack<?> getDisplayed()
{
return this.configuredItem;
}
@Override
@ -397,4 +368,42 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
{
return false;
}
protected List<ResourceLocation> selectModel(List<ResourceLocation> off, List<ResourceLocation> on, List<ResourceLocation> hasChannel,
List<ResourceLocation> lockedOff, List<ResourceLocation> lockedOn, List<ResourceLocation> lockedHasChannel) {
if( isActive() )
{
if( isLocked() )
{
return lockedHasChannel;
}
else
{
return hasChannel;
}
}
else if( isPowered() )
{
if( isLocked() )
{
return lockedOn;
}
else
{
return on;
}
}
else
{
if( isLocked() )
{
return lockedOff;
}
else
{
return off;
}
}
}
}

View File

@ -20,8 +20,11 @@ package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.api.util.AEColor;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;
/**
@ -36,6 +39,10 @@ import appeng.api.util.AEColor;
*/
public abstract class AbstractPartPanel extends AbstractPartReporting
{
@PartModels
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/monitor_base" );
public AbstractPartPanel( final ItemStack is )
{
super( is, false );

View File

@ -20,6 +20,7 @@ package appeng.parts.reporting;
import java.io.IOException;
import java.util.List;
import io.netty.buffer.ByteBuf;
@ -28,6 +29,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@ -289,6 +291,22 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
}
}
protected List<ResourceLocation> selectModel( List<ResourceLocation> offModels, List<ResourceLocation> onModels, List<ResourceLocation> hasChannelModels )
{
if( isActive() )
{
return hasChannelModels;
}
else if( isPowered() )
{
return onModels;
}
else
{
return offModels;
}
}
public final int getClientFlags()
{
return this.clientFlags;

View File

@ -22,18 +22,23 @@ package appeng.parts.reporting;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
@ -42,6 +47,23 @@ import appeng.util.item.AEItemStack;
public class PartConversionMonitor extends AbstractPartMonitor
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_on" );
@PartModels
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_locked_off" );
@PartModels
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_locked_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
public static final List<ResourceLocation> MODELS_LOCKED_OFF = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_LOCKED_ON = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_LOCKED_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL );
@Reflected
public PartConversionMonitor( final ItemStack is )
{
@ -160,4 +182,12 @@ public class PartConversionMonitor extends AbstractPartMonitor
}
}
}
@Override
public List<ResourceLocation> getStaticModels()
{
return selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL );
}
}

View File

@ -21,18 +21,33 @@ package appeng.parts.reporting;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.tile.inventory.AppEngInternalInventory;
public class PartCraftingTerminal extends AbstractPartTerminal
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/terminal_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/terminal_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory( this, 9 );
@Reflected
@ -98,4 +113,11 @@ public class PartCraftingTerminal extends AbstractPartTerminal
}
return super.getInventoryByName( name );
}
@Override
public List<ResourceLocation> getStaticModels()
{
return selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
}
}

View File

@ -19,14 +19,29 @@
package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
public class PartDarkPanel extends AbstractPartPanel
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_dark_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_dark_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON );
@Reflected
public PartDarkPanel( final ItemStack is )
{
@ -38,4 +53,11 @@ public class PartDarkPanel extends AbstractPartPanel
{
return this.getColor().mediumVariant;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return isPowered() ? MODELS_ON : MODELS_OFF;
}
}

View File

@ -19,17 +19,34 @@
package appeng.parts.reporting;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.items.parts.PartModels;
import appeng.util.Platform;
public class PartInterfaceTerminal extends AbstractPartDisplay
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
public PartInterfaceTerminal( final ItemStack is )
{
super( is );
@ -55,4 +72,11 @@ public class PartInterfaceTerminal extends AbstractPartDisplay
return false;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
}
}

View File

@ -19,14 +19,29 @@
package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
public class PartPanel extends AbstractPartPanel
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_bright_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_bright_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON );
@Reflected
public PartPanel( final ItemStack is )
{
@ -39,4 +54,10 @@ public class PartPanel extends AbstractPartPanel
return this.getColor().whiteVariant;
}
@Override
public List<ResourceLocation> getStaticModels()
{
return isPowered() ? MODELS_ON : MODELS_OFF;
}
}

View File

@ -21,22 +21,37 @@ package appeng.parts.reporting;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
public class PartPatternTerminal extends AbstractPartTerminal
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/pattern_terminal_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/pattern_terminal_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
private final AppEngInternalInventory crafting = new AppEngInternalInventory( this, 9 );
private final AppEngInternalInventory output = new AppEngInternalInventory( this, 3 );
private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
@ -197,4 +212,10 @@ public class PartPatternTerminal extends AbstractPartTerminal
return super.getInventoryByName( name );
}
@Override
public List<ResourceLocation> getStaticModels()
{
return selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
}
}

View File

@ -19,13 +19,27 @@
package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
public class PartSemiDarkPanel extends AbstractPartPanel
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_medium_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_medium_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON );
@Reflected
public PartSemiDarkPanel( final ItemStack is )
@ -40,4 +54,11 @@ public class PartSemiDarkPanel extends AbstractPartPanel
final int dark = this.getColor().mediumVariant;
return ( ( ( ( ( light >> 16 ) & 0xff ) + ( ( dark >> 16 ) & 0xff ) ) / 2 ) << 16 ) | ( ( ( ( ( light >> 8 ) & 0xff ) + ( ( dark >> 8 ) & 0xff ) ) / 2 ) << 8 ) | ( ( ( ( light ) & 0xff ) + ( ( dark ) & 0xff ) ) / 2 );
}
@Override
public List<ResourceLocation> getStaticModels()
{
return isPowered() ? MODELS_ON : MODELS_OFF;
}
}

View File

@ -19,9 +19,16 @@
package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.core.AppEng;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
/**
@ -33,9 +40,33 @@ import appeng.helpers.Reflected;
public class PartStorageMonitor extends AbstractPartMonitor
{
@PartModels
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_off" );
@PartModels
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_on" );
@PartModels
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_locked_off" );
@PartModels
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_locked_on" );
public static final List<ResourceLocation> MODELS_OFF = ImmutableList.of( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_ON = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
public static final List<ResourceLocation> MODELS_LOCKED_OFF = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF );
public static final List<ResourceLocation> MODELS_LOCKED_ON = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON );
public static final List<ResourceLocation> MODELS_LOCKED_HAS_CHANNEL = ImmutableList.of( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL );
@Reflected
public PartStorageMonitor( final ItemStack is )
{
super( is );
}
@Override
public List<ResourceLocation> getStaticModels()
{
return selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL );
}
}

Some files were not shown because too many files have changed in this diff Show More