Fixes #2376: Implemented coloring on color applicator.
This commit is contained in:
parent
cfbc6b4543
commit
202dff3a96
|
@ -36,12 +36,7 @@ import appeng.client.render.cablebus.CubeBuilder;
|
||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
|
|
||||||
|
|
||||||
/**
|
class BiometricCardBakedModel implements IPerspectiveAwareModel
|
||||||
* @author Sebastian
|
|
||||||
* @version rv3 - 10.10.2016
|
|
||||||
* @since rv3 10.10.2016
|
|
||||||
*/
|
|
||||||
public class BiometricCardBakedModel implements IPerspectiveAwareModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
private final VertexFormat format;
|
private final VertexFormat format;
|
||||||
|
@ -58,12 +53,12 @@ public class BiometricCardBakedModel implements IPerspectiveAwareModel
|
||||||
|
|
||||||
private final ImmutableList<BakedQuad> generalQuads;
|
private final ImmutableList<BakedQuad> generalQuads;
|
||||||
|
|
||||||
public BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||||
{
|
{
|
||||||
this( format, baseModel, texture, 0, transforms );
|
this( format, baseModel, texture, 0, transforms );
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, int hash, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
BiometricCardBakedModel( VertexFormat format, IBakedModel baseModel, TextureAtlasSprite texture, int hash, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms )
|
||||||
{
|
{
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.baseModel = baseModel;
|
this.baseModel = baseModel;
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
package appeng.client.render.model;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.vecmath.Matrix4f;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
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 net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||||
|
import net.minecraftforge.common.model.TRSRTransformation;
|
||||||
|
|
||||||
|
|
||||||
|
class ColorApplicatorBakedModel implements IPerspectiveAwareModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private final IBakedModel baseModel;
|
||||||
|
|
||||||
|
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
|
||||||
|
|
||||||
|
private final EnumMap<EnumFacing, List<BakedQuad>> quadsBySide;
|
||||||
|
|
||||||
|
private final List<BakedQuad> generalQuads;
|
||||||
|
|
||||||
|
ColorApplicatorBakedModel( IBakedModel baseModel, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map,
|
||||||
|
TextureAtlasSprite texDark, TextureAtlasSprite texMedium, TextureAtlasSprite texBright )
|
||||||
|
{
|
||||||
|
this.baseModel = baseModel;
|
||||||
|
this.transforms = map;
|
||||||
|
|
||||||
|
// Put the tint indices in... Since this is an item model, we are ignoring rand
|
||||||
|
this.generalQuads = fixQuadTint( null, texDark, texMedium, texBright );
|
||||||
|
this.quadsBySide = new EnumMap<>( EnumFacing.class );
|
||||||
|
for( EnumFacing facing : EnumFacing.values() )
|
||||||
|
{
|
||||||
|
this.quadsBySide.put( facing, fixQuadTint( facing, texDark, texMedium, texBright ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BakedQuad> fixQuadTint( EnumFacing facing, TextureAtlasSprite texDark, TextureAtlasSprite texMedium, TextureAtlasSprite texBright )
|
||||||
|
{
|
||||||
|
List<BakedQuad> quads = baseModel.getQuads( null, facing, 0 );
|
||||||
|
List<BakedQuad> result = new ArrayList<>( quads.size() );
|
||||||
|
for( BakedQuad quad : quads )
|
||||||
|
{
|
||||||
|
int tint;
|
||||||
|
|
||||||
|
if( quad.getSprite() == texDark )
|
||||||
|
{
|
||||||
|
tint = 1;
|
||||||
|
}
|
||||||
|
else if( quad.getSprite() == texMedium )
|
||||||
|
{
|
||||||
|
tint = 2;
|
||||||
|
}
|
||||||
|
else if( quad.getSprite() == texBright )
|
||||||
|
{
|
||||||
|
tint = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.add( quad );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BakedQuad newQuad = new BakedQuad(
|
||||||
|
quad.getVertexData(),
|
||||||
|
tint,
|
||||||
|
quad.getFace(),
|
||||||
|
quad.getSprite(),
|
||||||
|
quad.shouldApplyDiffuseLighting(),
|
||||||
|
quad.getFormat()
|
||||||
|
);
|
||||||
|
result.add( newQuad );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
|
||||||
|
{
|
||||||
|
if( side == null )
|
||||||
|
{
|
||||||
|
return generalQuads;
|
||||||
|
}
|
||||||
|
return this.quadsBySide.get( side );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAmbientOcclusion()
|
||||||
|
{
|
||||||
|
return baseModel.isAmbientOcclusion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGui3d()
|
||||||
|
{
|
||||||
|
return baseModel.isGui3d();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBuiltInRenderer()
|
||||||
|
{
|
||||||
|
return baseModel.isBuiltInRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextureAtlasSprite getParticleTexture()
|
||||||
|
{
|
||||||
|
return baseModel.getParticleTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemCameraTransforms getItemCameraTransforms()
|
||||||
|
{
|
||||||
|
return baseModel.getItemCameraTransforms();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemOverrideList getOverrides()
|
||||||
|
{
|
||||||
|
return baseModel.getOverrides();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pair<? extends IBakedModel, Matrix4f> handlePerspective( ItemCameraTransforms.TransformType type )
|
||||||
|
{
|
||||||
|
return MapWrapper.handlePerspective( this, transforms, type );
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package appeng.client.render.model;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||||
|
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.IPerspectiveAwareModel;
|
||||||
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
|
import net.minecraftforge.common.model.IModelState;
|
||||||
|
import net.minecraftforge.common.model.TRSRTransformation;
|
||||||
|
|
||||||
|
import appeng.core.AppEng;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A color applicator uses the base model, and extends it with additional layers that are colored according to the selected color of the applicator.
|
||||||
|
*/
|
||||||
|
public class ColorApplicatorModel implements IModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "item/color_applicator_colored" );
|
||||||
|
|
||||||
|
private static final ResourceLocation TEXTURE_DARK = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_dark" );
|
||||||
|
private static final ResourceLocation TEXTURE_MEDIUM = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_medium" );
|
||||||
|
private static final ResourceLocation TEXTURE_BRIGHT = new ResourceLocation( AppEng.MOD_ID, "items/color_applicator_tip_bright" );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ResourceLocation> getDependencies()
|
||||||
|
{
|
||||||
|
return Collections.singletonList( MODEL_BASE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ResourceLocation> getTextures()
|
||||||
|
{
|
||||||
|
return ImmutableList.of(
|
||||||
|
TEXTURE_DARK,
|
||||||
|
TEXTURE_MEDIUM,
|
||||||
|
TEXTURE_BRIGHT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||||
|
{
|
||||||
|
IBakedModel baseModel = getBaseModel( state, format, bakedTextureGetter );
|
||||||
|
|
||||||
|
TextureAtlasSprite texDark = bakedTextureGetter.apply( TEXTURE_DARK );
|
||||||
|
TextureAtlasSprite texMedium = bakedTextureGetter.apply( TEXTURE_MEDIUM );
|
||||||
|
TextureAtlasSprite texBright = bakedTextureGetter.apply( TEXTURE_BRIGHT );
|
||||||
|
|
||||||
|
ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms( state );
|
||||||
|
|
||||||
|
return new ColorApplicatorBakedModel( baseModel, map, texDark, texMedium, texBright );
|
||||||
|
}
|
||||||
|
|
||||||
|
private IBakedModel getBaseModel( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||||
|
{
|
||||||
|
// Load the base model
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ModelLoaderRegistry.getModel( MODEL_BASE ).bake( state, format, bakedTextureGetter );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
throw new RuntimeException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModelState getDefaultState()
|
||||||
|
{
|
||||||
|
return TRSRTransformation.identity();
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,6 +49,7 @@ import appeng.items.tools.ToolMemoryCard;
|
||||||
import appeng.items.tools.ToolNetworkTool;
|
import appeng.items.tools.ToolNetworkTool;
|
||||||
import appeng.items.tools.powered.ToolChargedStaff;
|
import appeng.items.tools.powered.ToolChargedStaff;
|
||||||
import appeng.items.tools.powered.ToolColorApplicator;
|
import appeng.items.tools.powered.ToolColorApplicator;
|
||||||
|
import appeng.items.tools.powered.ToolColorApplicatorRendering;
|
||||||
import appeng.items.tools.powered.ToolEntropyManipulator;
|
import appeng.items.tools.powered.ToolEntropyManipulator;
|
||||||
import appeng.items.tools.powered.ToolMatterCannon;
|
import appeng.items.tools.powered.ToolMatterCannon;
|
||||||
import appeng.items.tools.powered.ToolPortableCell;
|
import appeng.items.tools.powered.ToolPortableCell;
|
||||||
|
@ -156,6 +157,7 @@ public final class ApiItems implements IItems
|
||||||
this.colorApplicator = powerTools.item( "color_applicator", ToolColorApplicator::new )
|
this.colorApplicator = powerTools.item( "color_applicator", ToolColorApplicator::new )
|
||||||
.addFeatures( AEFeature.ColorApplicator )
|
.addFeatures( AEFeature.ColorApplicator )
|
||||||
.dispenserBehavior( DispenserBlockTool::new )
|
.dispenserBehavior( DispenserBlockTool::new )
|
||||||
|
.rendering( new ToolColorApplicatorRendering() )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
this.biometricCard = registry.item( "biometric_card", ToolBiometricCard::new )
|
this.biometricCard = registry.item( "biometric_card", ToolBiometricCard::new )
|
||||||
|
|
|
@ -3,6 +3,8 @@ package appeng.items.tools;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import appeng.bootstrap.IItemRendering;
|
import appeng.bootstrap.IItemRendering;
|
||||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||||
|
@ -13,9 +15,10 @@ import appeng.core.AppEng;
|
||||||
public class ToolBiometricCardRendering extends ItemRenderingCustomizer
|
public class ToolBiometricCardRendering extends ItemRenderingCustomizer
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final ResourceLocation MODEL = new ResourceLocation( AppEng.MOD_ID, "builtin/biometric_card" );
|
private static final ResourceLocation MODEL = new ResourceLocation( AppEng.MOD_ID, "builtin/biometric_card" );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
public void customize( IItemRendering rendering )
|
public void customize( IItemRendering rendering )
|
||||||
{
|
{
|
||||||
rendering.builtInModel( "models/item/builtin/biometric_card", new BiometricCardModel() );
|
rendering.builtInModel( "models/item/builtin/biometric_card", new BiometricCardModel() );
|
||||||
|
|
|
@ -101,11 +101,6 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||||
public ToolColorApplicator()
|
public ToolColorApplicator()
|
||||||
{
|
{
|
||||||
super( AEConfig.instance.colorApplicatorBattery );
|
super( AEConfig.instance.colorApplicatorBattery );
|
||||||
if( Platform.isClient() )
|
|
||||||
{
|
|
||||||
// TODO - color applicator
|
|
||||||
// MinecraftForgeClient.registerItemRenderer( this, new ToolColorApplicatorRender() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package appeng.items.tools.powered;
|
||||||
|
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
import appeng.api.util.AEColor;
|
||||||
|
import appeng.bootstrap.IItemRendering;
|
||||||
|
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||||
|
import appeng.client.render.model.ColorApplicatorModel;
|
||||||
|
import appeng.core.AppEng;
|
||||||
|
|
||||||
|
|
||||||
|
public class ToolColorApplicatorRendering extends ItemRenderingCustomizer
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final ModelResourceLocation MODEL_COLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "builtin/color_applicator_colored" ), "inventory" );
|
||||||
|
private static final ModelResourceLocation MODEL_UNCOLORED = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "color_applicator_uncolored" ), "inventory" );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
public void customize( IItemRendering rendering )
|
||||||
|
{
|
||||||
|
rendering.builtInModel( "models/item/builtin/color_applicator_colored", new ColorApplicatorModel() );
|
||||||
|
rendering.variants( MODEL_COLORED, MODEL_UNCOLORED );
|
||||||
|
rendering.color( this::getColor );
|
||||||
|
rendering.meshDefinition( this::getMesh );
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModelResourceLocation getMesh( ItemStack itemStack )
|
||||||
|
{
|
||||||
|
// If the stack has no color, don't use the colored model since the impact of calling getColor for every quad is extremely high,
|
||||||
|
// if the stack tries to re-search its inventory for a new paintball everytime
|
||||||
|
AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
|
||||||
|
return ( col != null ) ? MODEL_COLORED : MODEL_UNCOLORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getColor( ItemStack itemStack, int idx )
|
||||||
|
{
|
||||||
|
if( idx == 0 )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
final AEColor col = ( (ToolColorApplicator) itemStack.getItem() ).getActiveColor( itemStack );
|
||||||
|
|
||||||
|
if( col == null )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( idx )
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return col.blackVariant;
|
||||||
|
case 2:
|
||||||
|
return col.mediumVariant;
|
||||||
|
case 3:
|
||||||
|
return col.whiteVariant;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "appliedenergistics2:items/color_applicator",
|
||||||
|
"layer1": "appliedenergistics2:items/color_applicator_tip_dark",
|
||||||
|
"layer2": "appliedenergistics2:items/color_applicator_tip_medium",
|
||||||
|
"layer3": "appliedenergistics2:items/color_applicator_tip_bright"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "item/generated",
|
|
||||||
"textures": {
|
|
||||||
"layer0": "appliedenergistics2:items/color_applicator_tip_dark"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "item/generated",
|
|
||||||
"textures": {
|
|
||||||
"layer0": "appliedenergistics2:items/color_applicator_tip_light"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "item/generated",
|
|
||||||
"textures": {
|
|
||||||
"layer0": "appliedenergistics2:items/color_applicator_tip_medium"
|
|
||||||
}
|
|
||||||
}
|
|
Before Width: | Height: | Size: 252 B After Width: | Height: | Size: 252 B |
Loading…
Reference in a new issue