mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Fix custom blocks not being able to be modified in singleplayer, also set LastModifiedTime of files when applying a patch to the date of the patch.
This commit is contained in:
parent
3e05ba60de
commit
40878872bf
@ -148,6 +148,7 @@
|
||||
<Compile Include="Entities\Components\HacksComponent.cs" />
|
||||
<Compile Include="Entities\Components\InterpolatedComponent.cs" />
|
||||
<Compile Include="Entities\Components\PhysicsComponent.cs" />
|
||||
<Compile Include="Entities\Components\ShadowComponent.cs" />
|
||||
<Compile Include="Entities\Entity.Bounds.cs" />
|
||||
<Compile Include="Entities\Entity.cs" />
|
||||
<Compile Include="Entities\EntityList.cs" />
|
||||
@ -155,7 +156,6 @@
|
||||
<Compile Include="Entities\LocalPlayer.Physics.cs" />
|
||||
<Compile Include="Entities\LocationUpdate.cs" />
|
||||
<Compile Include="Entities\NetPlayer.cs" />
|
||||
<Compile Include="Entities\Player.Shadows.cs" />
|
||||
<Compile Include="Events\EntityEvents.cs" />
|
||||
<Compile Include="Events\Events.cs" />
|
||||
<Compile Include="Events\MapEvents.cs" />
|
||||
|
@ -5,11 +5,19 @@ using OpenTK;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
partial class Player {
|
||||
/// <summary> Entity component that draws square and circle shadows beneath entities. </summary>
|
||||
public unsafe sealed class ShadowComponent {
|
||||
|
||||
internal static bool boundShadowTex = false;
|
||||
Game game;
|
||||
Entity entity;
|
||||
public ShadowComponent( Game game, Entity entity ) {
|
||||
this.game = game;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
internal unsafe void DrawShadow( EntityShadow mode ) {
|
||||
internal void Draw() {
|
||||
EntityShadow mode = game.Players.ShadowMode;
|
||||
Vector3 Position = entity.Position;
|
||||
float posX = Position.X, posZ = Position.Z;
|
||||
int posY = Math.Min( (int)Position.Y, game.Map.Height - 1 );
|
||||
int index = 0, vb = 0;
|
||||
@ -49,7 +57,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
if( index == 0 ) return;
|
||||
CheckShadowTexture();
|
||||
CheckShadowTexture( game.Graphics );
|
||||
|
||||
if( !boundShadowTex ) {
|
||||
game.Graphics.BindTexture( shadowTex );
|
||||
@ -58,11 +66,12 @@ namespace ClassicalSharp {
|
||||
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, verts, index, index * 6 / 4 );
|
||||
}
|
||||
|
||||
unsafe bool CalculateShadow( Vector3I* coords, ref int coordsCount, float x, float z, int posY, ref ShadowData data ) {
|
||||
bool CalculateShadow( Vector3I* coords, ref int coordsCount, float x, float z, int posY, ref ShadowData data ) {
|
||||
data = new ShadowData();
|
||||
int blockX = Utils.Floor( x ), blockZ = Utils.Floor( z );
|
||||
Vector3I p = new Vector3I( blockX, 0, blockZ );
|
||||
BlockInfo info = game.BlockInfo;
|
||||
Vector3 Position = entity.Position;
|
||||
|
||||
if( Position.Y < 0 ) return false;
|
||||
for( int i = 0; i < 4; i++ )
|
||||
@ -96,26 +105,7 @@ namespace ClassicalSharp {
|
||||
return game.Map.GetBlock( x, y, z );
|
||||
}
|
||||
|
||||
int shadowTex = -1;
|
||||
unsafe void CheckShadowTexture() {
|
||||
if( shadowTex != -1 ) return;
|
||||
const int size = 128, half = size / 2;
|
||||
using( Bitmap bmp = new Bitmap( size, size ) )
|
||||
using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
|
||||
{
|
||||
int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
|
||||
int outPix = inPix & 0xFFFFFF;
|
||||
for( int y = 0; y < fastBmp.Height; y++ ) {
|
||||
int* row = fastBmp.GetRowPtr( y );
|
||||
for( int x = 0; x < fastBmp.Width; x++ ) {
|
||||
double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
|
||||
(half - (y + 0.5)) * (half - (y + 0.5));
|
||||
row[x] = dist < half * half ? inPix : outPix;
|
||||
}
|
||||
}
|
||||
shadowTex = game.Graphics.CreateTexture( fastBmp );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DraqSquareShadow( VertexPos3fTex2fCol4b[] verts, ref int index, float y, byte alpha, float x, float z ) {
|
||||
FastColour col = FastColour.White; col.A = alpha;
|
||||
@ -163,5 +153,28 @@ namespace ClassicalSharp {
|
||||
static bool lequal(float a, float b) {
|
||||
return a < b || Math.Abs(a - b) < 0.001f;
|
||||
}
|
||||
|
||||
|
||||
internal static bool boundShadowTex = false;
|
||||
internal static int shadowTex = -1;
|
||||
static void CheckShadowTexture( IGraphicsApi graphics ) {
|
||||
if( shadowTex != -1 ) return;
|
||||
const int size = 128, half = size / 2;
|
||||
using( Bitmap bmp = new Bitmap( size, size ) )
|
||||
using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
|
||||
{
|
||||
int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
|
||||
int outPix = inPix & 0xFFFFFF;
|
||||
for( int y = 0; y < fastBmp.Height; y++ ) {
|
||||
int* row = fastBmp.GetRowPtr( y );
|
||||
for( int x = 0; x < fastBmp.Width; x++ ) {
|
||||
double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
|
||||
(half - (y + 0.5)) * (half - (y + 0.5));
|
||||
row[x] = dist < half * half ? inPix : outPix;
|
||||
}
|
||||
}
|
||||
shadowTex = graphics.CreateTexture( fastBmp );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -142,12 +142,12 @@ namespace ClassicalSharp {
|
||||
|
||||
public void DrawShadows() {
|
||||
if( ShadowMode == EntityShadow.None ) return;
|
||||
Player.boundShadowTex = false;
|
||||
ShadowComponent.boundShadowTex = false;
|
||||
game.Graphics.AlphaArgBlend = true;
|
||||
game.Graphics.DepthWrite = false;
|
||||
game.Graphics.AlphaBlending = true;
|
||||
|
||||
Players[255].DrawShadow( ShadowMode );
|
||||
Players[255].shadow.Draw();
|
||||
if( ShadowMode == EntityShadow.CircleAll )
|
||||
DrawOtherShadows();
|
||||
game.Graphics.AlphaArgBlend = false;
|
||||
@ -158,7 +158,7 @@ namespace ClassicalSharp {
|
||||
void DrawOtherShadows() {
|
||||
for( int i = 0; i < 255; i++) {
|
||||
if( Players[i] == null ) continue;
|
||||
Players[i].DrawShadow( ShadowMode );
|
||||
Players[i].shadow.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,14 @@ namespace ClassicalSharp {
|
||||
public string DisplayName, SkinName, SkinIdentifier;
|
||||
public SkinType SkinType;
|
||||
internal AnimatedComponent anim;
|
||||
internal ShadowComponent shadow;
|
||||
|
||||
public Player( Game game ) : base( game ) {
|
||||
this.game = game;
|
||||
StepSize = 0.5f;
|
||||
SkinType = game.DefaultPlayerSkinType;
|
||||
anim = new AnimatedComponent( game, this );
|
||||
shadow = new ShadowComponent( game, this );
|
||||
SetModel( "humanoid" );
|
||||
}
|
||||
|
||||
@ -38,8 +40,6 @@ namespace ClassicalSharp {
|
||||
public override void Despawn() {
|
||||
game.Graphics.DeleteTexture( ref PlayerTextureId );
|
||||
game.Graphics.DeleteTexture( ref nameTex.ID );
|
||||
if( shadowTex != -1 )
|
||||
game.Graphics.DeleteTexture( ref shadowTex );
|
||||
}
|
||||
|
||||
protected void InitRenderingData() {
|
||||
|
@ -162,6 +162,10 @@ namespace ClassicalSharp {
|
||||
info.InitLightOffsets();
|
||||
game.Events.RaiseBlockDefinitionChanged();
|
||||
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
|
||||
|
||||
game.Inventory.CanPlace.SetNotOverridable( true, id );
|
||||
game.Inventory.CanDelete.SetNotOverridable( true, id );
|
||||
game.Events.RaiseBlockPermissionsChanged();
|
||||
}
|
||||
}
|
||||
}
|
@ -124,6 +124,7 @@ namespace Launcher {
|
||||
|
||||
string path = dx ? build.DirectXPath : build.OpenGLPath;
|
||||
Utils.LogDebug( "Updating to: " + path );
|
||||
Patcher.PatchTime = build.TimeBuilt;
|
||||
Patcher.Update( path );
|
||||
game.ShouldExit = true;
|
||||
game.ShouldUpdate = true;
|
||||
|
@ -4,12 +4,15 @@ using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ClassicalSharp;
|
||||
using ClassicalSharp.TexturePack;
|
||||
|
||||
namespace Launcher.Updater {
|
||||
|
||||
public static class Patcher {
|
||||
|
||||
public static DateTime PatchTime;
|
||||
|
||||
public static void Update( string dir ) {
|
||||
using( WebClient client = new WebClient() ) {
|
||||
byte[] zipData = client.DownloadData( UpdateCheckTask.UpdatesUri + dir );
|
||||
@ -25,9 +28,9 @@ namespace Launcher.Updater {
|
||||
info = new ProcessStartInfo( "cmd.exe", "/c update.bat" );
|
||||
} else {
|
||||
string path = Path.Combine( Program.AppDirectory, "update.sh" );
|
||||
File.WriteAllText( path, Scripts.BashFile.Replace( "\r\n", "\n" ) );
|
||||
File.WriteAllText( path, Scripts.BashFile.Replace( "\r\n", "\n" ) );
|
||||
const int flags = 0x7;// read | write | executable
|
||||
int code = chmod( path, (flags << 6) | (flags << 3) | 4 );
|
||||
int code = chmod( path, (flags << 6) | (flags << 3) | 4 );
|
||||
if( code != 0 )
|
||||
throw new InvalidOperationException( "chmod returned : " + code );
|
||||
info = new ProcessStartInfo( "xterm", '"' + path + '"');
|
||||
@ -50,11 +53,19 @@ namespace Launcher.Updater {
|
||||
reader.Extract( stream );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
||||
string path = Path.Combine( Program.AppDirectory, "CS_Update" );
|
||||
path = Path.Combine( path, Path.GetFileName( filename ) );
|
||||
File.WriteAllBytes( path, data );
|
||||
|
||||
try {
|
||||
File.SetLastWriteTimeUtc( path, PatchTime );
|
||||
} catch( IOException ex ) {
|
||||
ErrorHandler.LogError( "I/O exception when trying to set modified time for: " + filename, ex );
|
||||
} catch( UnauthorizedAccessException ex ) {
|
||||
ErrorHandler.LogError( "Permissions exception when trying to set modified time for: " + filename, ex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user