Fixes Paintball Item Rendering (#48)

* Added a way to register a custom ItemMeshDefinition for items, including registration of custom variants.

* Moved color handling for paint balls into the paint ball class and implemented the correct model selection logic for displaying the items.
This commit is contained in:
shartte
2016-08-16 17:55:56 +02:00
committed by Elix_x
parent 115f73de2e
commit 838691d924
4 changed files with 101 additions and 43 deletions
+5 -28
View File
@@ -31,7 +31,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@@ -131,7 +131,10 @@ public class ClientHelper extends ServerHelper
}
}
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemPaintBallColor(), Api.INSTANCE.definitions().items().paintBall().maybeItem().get() );
// Register color handling for paintball items
ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
Item paintballItem = Api.INSTANCE.definitions().items().paintBall().maybeItem().get();
itemColors.registerItemColorHandler( ItemPaintBall::getColorFromItemstack, paintballItem );
}
@Override
@@ -466,30 +469,4 @@ public class ClientHelper extends ServerHelper
}
}
public class ItemPaintBallColor implements IItemColor
{
@Override
public int getColorFromItemstack( ItemStack stack, int tintIndex )
{
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
final int colorValue = stack.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
final int r = ( colorValue >> 16 ) & 0xff;
final int g = ( colorValue >> 8 ) & 0xff;
final int b = ( colorValue ) & 0xff;
if( stack.getItemDamage() >= 20 )
{
final float fail = 0.7f;
final int full = (int) ( 255 * 0.3 );
return (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
}
else
{
return r << 16 | g << 8 | b | 0xff << 24;
}
}
}
}