mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Add ability to change entity textures with local texture packs.
This commit is contained in:
parent
670a887218
commit
5a8ec25957
@ -17,7 +17,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftWing = MakeWing( -0.25f, -0.1875f );
|
||||
RightWing = MakeWing( 0.1875f, 0.25f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "chicken.png" );
|
||||
if( cache.ChickenTexId <= 0 )
|
||||
cache.ChickenTexId = graphics.CreateTexture( "chicken.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeHead() {
|
||||
@ -61,7 +62,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.ChickenTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
graphics.AlphaTest = true;
|
||||
|
||||
@ -75,10 +76,6 @@ namespace ClassicalSharp.Model {
|
||||
DrawRotate( 0.1875f, 0.6875f, 0, 0, 0, Math.Abs( p.rightArmXRot ), RightWing );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Head2, Head3, Torso, LeftLeg, RightLeg, LeftWing, RightWing;
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftLegBack = MakeLeg( -0.25f, 0, 0.125f, 0.375f );
|
||||
RightLegBack = MakeLeg( 0, 0.25f, 0.125f, 0.375f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "creeper.png" );
|
||||
if( cache.CreeperTexId <= 0 )
|
||||
cache.CreeperTexId = graphics.CreateTexture( "creeper.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeHead() {
|
||||
@ -44,7 +45,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.CreeperTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
DrawRotate( 0, 1.125f, 0, -p.PitchRadians, 0, 0, Head );
|
||||
@ -56,10 +57,6 @@ namespace ClassicalSharp.Model {
|
||||
graphics.AlphaTest = true;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Torso, LeftLegFront, RightLegFront, LeftLegBack, RightLegBack;
|
||||
}
|
||||
}
|
@ -42,9 +42,8 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected abstract void DrawPlayerModel( Player p );
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public int DefaultTexId;
|
||||
public virtual void Dispose() {
|
||||
}
|
||||
|
||||
protected FastColour col;
|
||||
protected VertexPos3fTex2fCol4b[] vertices;
|
||||
|
@ -16,13 +16,15 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
public void InitCache() {
|
||||
vertices = new VertexPos3fTex2fCol4b[384];
|
||||
vb = game.Graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, vertices.Length );
|
||||
vb = api.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, vertices.Length );
|
||||
cache["humanoid"] = new PlayerModel( game );
|
||||
}
|
||||
|
||||
internal int vb;
|
||||
internal VertexPos3fTex2fCol4b[] vertices;
|
||||
Dictionary<string, IModel> cache = new Dictionary<string, IModel>();
|
||||
internal int ChickenTexId, CreeperTexId, PigTexId, SheepTexId,
|
||||
SkeletonTexId, SpiderTexId, ZombieTexId, SheepFurTexId, HumanoidTexId;
|
||||
|
||||
public IModel GetModel( string modelName ) {
|
||||
IModel model;
|
||||
@ -72,7 +74,16 @@ namespace ClassicalSharp.Model {
|
||||
foreach( var entry in cache ) {
|
||||
entry.Value.Dispose();
|
||||
}
|
||||
game.Graphics.DeleteDynamicVb( vb );
|
||||
api.DeleteDynamicVb( vb );
|
||||
api.DeleteTexture( ref ChickenTexId );
|
||||
api.DeleteTexture( ref CreeperTexId );
|
||||
api.DeleteTexture( ref PigTexId );
|
||||
api.DeleteTexture( ref SheepTexId );
|
||||
api.DeleteTexture( ref SkeletonTexId );
|
||||
api.DeleteTexture( ref SpiderTexId );
|
||||
api.DeleteTexture( ref ZombieTexId );
|
||||
api.DeleteTexture( ref SheepFurTexId );
|
||||
api.DeleteTexture( ref HumanoidTexId );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftLegBack = MakeLeg( -0.3125f, -0.0625f, 0.3125f, 0.5625f );
|
||||
RightLegBack = MakeLeg( 0.0625f, 0.3125f, 0.3125f, 0.5625f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "pig.png" );
|
||||
if( cache.PigTexId <= 0 )
|
||||
cache.PigTexId = graphics.CreateTexture( "pig.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeHead() {
|
||||
@ -44,7 +45,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.PigTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
DrawRotate( 0, 0.75f, -0.375f, -p.PitchRadians, 0, 0, Head );
|
||||
@ -56,10 +57,6 @@ namespace ClassicalSharp.Model {
|
||||
graphics.AlphaTest = true;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Torso, LeftLegFront, RightLegFront, LeftLegBack, RightLegBack;
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
using( Bitmap bmp = new Bitmap( "char.png" ) ) {
|
||||
window.DefaultPlayerSkinType = Utils.GetSkinType( bmp );
|
||||
DefaultTexId = graphics.CreateTexture( bmp );
|
||||
cache.HumanoidTexId = graphics.CreateTexture( bmp );
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ namespace ClassicalSharp.Model {
|
||||
ModelSet model;
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.PlayerTextureId <= 0 ? DefaultTexId : p.PlayerTextureId;
|
||||
int texId = p.PlayerTextureId <= 0 ? cache.HumanoidTexId : p.PlayerTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
SkinType skinType = p.SkinType;
|
||||
@ -104,10 +104,6 @@ namespace ClassicalSharp.Model {
|
||||
DrawRotate( 0, 1.4375f, 0, -p.PitchRadians, 0, 0, model.Hat );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
class ModelSet {
|
||||
|
||||
public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat;
|
||||
|
@ -27,8 +27,10 @@ namespace ClassicalSharp.Model {
|
||||
FurRightLegBack = MakeFurLeg( 0.03125f, 0.34375f, 0.28125f, 0.59375f );
|
||||
}
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "sheep.png" );
|
||||
furTextureId = graphics.CreateTexture( "sheep_fur.png" );
|
||||
if( cache.SheepTexId <= 0 )
|
||||
cache.SheepTexId = graphics.CreateTexture( "sheep.png" );
|
||||
if( cache.SheepFurTexId <= 0 )
|
||||
cache.SheepFurTexId = graphics.CreateTexture( "sheep_fur.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeHead() {
|
||||
@ -69,7 +71,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.SheepTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
DrawRotate( 0, 1.125f, -0.5f, -p.PitchRadians, 0, 0, Head );
|
||||
@ -80,7 +82,7 @@ namespace ClassicalSharp.Model {
|
||||
DrawRotate( 0, 0.75f, 0.4375f, p.leftLegXRot, 0, 0, RightLegBack );
|
||||
graphics.AlphaTest = true;
|
||||
if( Fur ) {
|
||||
graphics.BindTexture( furTextureId );
|
||||
graphics.BindTexture( cache.SheepFurTexId );
|
||||
DrawPart( FurTorso );
|
||||
DrawRotate( 0, 1.125f, -0.5f, -p.PitchRadians, 0, 0, FurHead );
|
||||
DrawRotate( 0, 0.75f, -0.3125f, p.leftLegXRot, 0, 0, FurLeftLegFront );
|
||||
@ -90,13 +92,6 @@ namespace ClassicalSharp.Model {
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
if( Fur ) {
|
||||
graphics.DeleteTexture( ref furTextureId );
|
||||
}
|
||||
}
|
||||
|
||||
ModelPart Head, Torso, LeftLegFront, RightLegFront, LeftLegBack, RightLegBack;
|
||||
ModelPart FurHead, FurTorso, FurLeftLegFront, FurRightLegFront, FurLeftLegBack, FurRightLegBack;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp.Model {
|
||||
@ -15,7 +14,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftArm = MakeLeftArm( 0.375f, 0.25f );
|
||||
RightArm = MakeRightArm( 0.25f, 0.375f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "skeleton.png" );
|
||||
if( cache.SkeletonTexId <= 0 )
|
||||
cache.SkeletonTexId = graphics.CreateTexture( "skeleton.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeLeftArm( float x1, float x2 ) {
|
||||
@ -57,7 +57,7 @@ namespace ClassicalSharp.Model {
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
graphics.AlphaTest = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.SkeletonTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head );
|
||||
@ -68,10 +68,6 @@ namespace ClassicalSharp.Model {
|
||||
DrawRotate( 0, 1.375f, 0, (float)Math.PI / 2, 0, p.rightArmZRot, RightArm );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm;
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp.Model {
|
||||
@ -14,7 +13,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftLeg = MakeLeg( -1.1875f, -0.1875f );
|
||||
RightLeg = MakeLeg( 0.1875f, 1.1875f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "spider.png" );
|
||||
if( cache.SpiderTexId <= 0 )
|
||||
cache.SpiderTexId = graphics.CreateTexture( "spider.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeHead() {
|
||||
@ -49,7 +49,7 @@ namespace ClassicalSharp.Model {
|
||||
const float eighthPi = (float)( Math.PI / 8 );
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.SpiderTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
graphics.AlphaTest = true;
|
||||
|
||||
@ -67,10 +67,6 @@ namespace ClassicalSharp.Model {
|
||||
DrawRotate( 0.1875f, 0.5f, 0, 0, quarterPi, -eighthPi, RightLeg );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Link, End, LeftLeg, RightLeg;
|
||||
}
|
||||
}
|
@ -15,7 +15,8 @@ namespace ClassicalSharp.Model {
|
||||
LeftArm = MakeLeftArm( 0.5f, 0.25f );
|
||||
RightArm = MakeRightArm( 0.25f, 0.5f );
|
||||
|
||||
DefaultTexId = graphics.CreateTexture( "zombie.png" );
|
||||
if( cache.ZombieTexId <= 0 )
|
||||
cache.ZombieTexId = graphics.CreateTexture( "zombie.png" );
|
||||
}
|
||||
|
||||
ModelPart MakeLeftArm( float x1, float x2 ) {
|
||||
@ -56,7 +57,7 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
protected override void DrawPlayerModel( Player p ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
|
||||
int texId = p.MobTextureId <= 0 ? cache.ZombieTexId : p.MobTextureId;
|
||||
graphics.BindTexture( texId );
|
||||
|
||||
DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head );
|
||||
@ -68,10 +69,6 @@ namespace ClassicalSharp.Model {
|
||||
graphics.AlphaTest = true;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphics.DeleteTexture( ref DefaultTexId );
|
||||
}
|
||||
|
||||
ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm;
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using ClassicalSharp.Model;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
|
||||
namespace ClassicalSharp.TexturePack {
|
||||
|
||||
@ -69,14 +71,44 @@ namespace ClassicalSharp.TexturePack {
|
||||
}
|
||||
}
|
||||
|
||||
/*ChickenTexId, CreeperTexId, PigTexId, SheepTexId,
|
||||
SkeletonTexId, SpiderTexId, ZombieTexId, SheepFurTexId, HumanoidTexId;*/
|
||||
void HandleZipEntry( string filename, byte[] data ) {
|
||||
Console.WriteLine( filename );
|
||||
MemoryStream stream = new MemoryStream( data );
|
||||
ModelCache cache = game.ModelCache;
|
||||
IGraphicsApi api = game.Graphics;
|
||||
|
||||
switch( filename ) {
|
||||
case "terrain.png":
|
||||
game.ChangeTerrainAtlas( new Bitmap( stream ) );
|
||||
break;
|
||||
game.ChangeTerrainAtlas( new Bitmap( stream ) ); break;
|
||||
case "chicken.png":
|
||||
UpdateTexture( ref cache.ChickenTexId, stream, false ); break;
|
||||
case "creeper.png":
|
||||
UpdateTexture( ref cache.CreeperTexId, stream, false ); break;
|
||||
case "pig.png":
|
||||
UpdateTexture( ref cache.PigTexId, stream, false ); break;
|
||||
case "sheep.png":
|
||||
UpdateTexture( ref cache.SheepTexId, stream, false ); break;
|
||||
case "skeleton.png":
|
||||
UpdateTexture( ref cache.SkeletonTexId, stream, false ); break;
|
||||
case "spider.png":
|
||||
UpdateTexture( ref cache.SpiderTexId, stream, false ); break;
|
||||
case "zombie.png":
|
||||
UpdateTexture( ref cache.ZombieTexId, stream, false ); break;
|
||||
case "sheep_fur.png":
|
||||
UpdateTexture( ref cache.SheepFurTexId, stream, false ); break;
|
||||
case "char.png":
|
||||
UpdateTexture( ref cache.HumanoidTexId, stream, true ); break;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {
|
||||
game.Graphics.DeleteTexture( ref texId );
|
||||
using( Bitmap bmp = new Bitmap( stream ) ) {
|
||||
if( setSkinType )
|
||||
game.DefaultPlayerSkinType = Utils.GetSkinType( bmp );
|
||||
texId = game.Graphics.CreateTexture( bmp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user