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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user