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
+17
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
{
}
+20
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
{
}
+1 -1
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
{
/**
@@ -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();
}
@@ -28,7 +28,6 @@ public enum BusSupport
{
CABLE,
DENSE_CABLE,
NO_PARTS
DENSE_CABLE
}
@@ -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 );
}
+34 -6
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();
}
}
@@ -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 ) );
}
}
+36 -7
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() );
}
}
+51
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
*/