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\HacksComponent.cs" />
|
||||||
<Compile Include="Entities\Components\InterpolatedComponent.cs" />
|
<Compile Include="Entities\Components\InterpolatedComponent.cs" />
|
||||||
<Compile Include="Entities\Components\PhysicsComponent.cs" />
|
<Compile Include="Entities\Components\PhysicsComponent.cs" />
|
||||||
|
<Compile Include="Entities\Components\ShadowComponent.cs" />
|
||||||
<Compile Include="Entities\Entity.Bounds.cs" />
|
<Compile Include="Entities\Entity.Bounds.cs" />
|
||||||
<Compile Include="Entities\Entity.cs" />
|
<Compile Include="Entities\Entity.cs" />
|
||||||
<Compile Include="Entities\EntityList.cs" />
|
<Compile Include="Entities\EntityList.cs" />
|
||||||
@ -155,7 +156,6 @@
|
|||||||
<Compile Include="Entities\LocalPlayer.Physics.cs" />
|
<Compile Include="Entities\LocalPlayer.Physics.cs" />
|
||||||
<Compile Include="Entities\LocationUpdate.cs" />
|
<Compile Include="Entities\LocationUpdate.cs" />
|
||||||
<Compile Include="Entities\NetPlayer.cs" />
|
<Compile Include="Entities\NetPlayer.cs" />
|
||||||
<Compile Include="Entities\Player.Shadows.cs" />
|
|
||||||
<Compile Include="Events\EntityEvents.cs" />
|
<Compile Include="Events\EntityEvents.cs" />
|
||||||
<Compile Include="Events\Events.cs" />
|
<Compile Include="Events\Events.cs" />
|
||||||
<Compile Include="Events\MapEvents.cs" />
|
<Compile Include="Events\MapEvents.cs" />
|
||||||
|
@ -5,11 +5,19 @@ using OpenTK;
|
|||||||
|
|
||||||
namespace ClassicalSharp {
|
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;
|
float posX = Position.X, posZ = Position.Z;
|
||||||
int posY = Math.Min( (int)Position.Y, game.Map.Height - 1 );
|
int posY = Math.Min( (int)Position.Y, game.Map.Height - 1 );
|
||||||
int index = 0, vb = 0;
|
int index = 0, vb = 0;
|
||||||
@ -49,7 +57,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( index == 0 ) return;
|
if( index == 0 ) return;
|
||||||
CheckShadowTexture();
|
CheckShadowTexture( game.Graphics );
|
||||||
|
|
||||||
if( !boundShadowTex ) {
|
if( !boundShadowTex ) {
|
||||||
game.Graphics.BindTexture( shadowTex );
|
game.Graphics.BindTexture( shadowTex );
|
||||||
@ -58,11 +66,12 @@ namespace ClassicalSharp {
|
|||||||
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, verts, index, index * 6 / 4 );
|
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();
|
data = new ShadowData();
|
||||||
int blockX = Utils.Floor( x ), blockZ = Utils.Floor( z );
|
int blockX = Utils.Floor( x ), blockZ = Utils.Floor( z );
|
||||||
Vector3I p = new Vector3I( blockX, 0, blockZ );
|
Vector3I p = new Vector3I( blockX, 0, blockZ );
|
||||||
BlockInfo info = game.BlockInfo;
|
BlockInfo info = game.BlockInfo;
|
||||||
|
Vector3 Position = entity.Position;
|
||||||
|
|
||||||
if( Position.Y < 0 ) return false;
|
if( Position.Y < 0 ) return false;
|
||||||
for( int i = 0; i < 4; i++ )
|
for( int i = 0; i < 4; i++ )
|
||||||
@ -96,26 +105,7 @@ namespace ClassicalSharp {
|
|||||||
return game.Map.GetBlock( x, y, z );
|
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 ) {
|
void DraqSquareShadow( VertexPos3fTex2fCol4b[] verts, ref int index, float y, byte alpha, float x, float z ) {
|
||||||
FastColour col = FastColour.White; col.A = alpha;
|
FastColour col = FastColour.White; col.A = alpha;
|
||||||
@ -163,5 +153,28 @@ namespace ClassicalSharp {
|
|||||||
static bool lequal(float a, float b) {
|
static bool lequal(float a, float b) {
|
||||||
return a < b || Math.Abs(a - b) < 0.001f;
|
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() {
|
public void DrawShadows() {
|
||||||
if( ShadowMode == EntityShadow.None ) return;
|
if( ShadowMode == EntityShadow.None ) return;
|
||||||
Player.boundShadowTex = false;
|
ShadowComponent.boundShadowTex = false;
|
||||||
game.Graphics.AlphaArgBlend = true;
|
game.Graphics.AlphaArgBlend = true;
|
||||||
game.Graphics.DepthWrite = false;
|
game.Graphics.DepthWrite = false;
|
||||||
game.Graphics.AlphaBlending = true;
|
game.Graphics.AlphaBlending = true;
|
||||||
|
|
||||||
Players[255].DrawShadow( ShadowMode );
|
Players[255].shadow.Draw();
|
||||||
if( ShadowMode == EntityShadow.CircleAll )
|
if( ShadowMode == EntityShadow.CircleAll )
|
||||||
DrawOtherShadows();
|
DrawOtherShadows();
|
||||||
game.Graphics.AlphaArgBlend = false;
|
game.Graphics.AlphaArgBlend = false;
|
||||||
@ -158,7 +158,7 @@ namespace ClassicalSharp {
|
|||||||
void DrawOtherShadows() {
|
void DrawOtherShadows() {
|
||||||
for( int i = 0; i < 255; i++) {
|
for( int i = 0; i < 255; i++) {
|
||||||
if( Players[i] == null ) continue;
|
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 string DisplayName, SkinName, SkinIdentifier;
|
||||||
public SkinType SkinType;
|
public SkinType SkinType;
|
||||||
internal AnimatedComponent anim;
|
internal AnimatedComponent anim;
|
||||||
|
internal ShadowComponent shadow;
|
||||||
|
|
||||||
public Player( Game game ) : base( game ) {
|
public Player( Game game ) : base( game ) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
StepSize = 0.5f;
|
StepSize = 0.5f;
|
||||||
SkinType = game.DefaultPlayerSkinType;
|
SkinType = game.DefaultPlayerSkinType;
|
||||||
anim = new AnimatedComponent( game, this );
|
anim = new AnimatedComponent( game, this );
|
||||||
|
shadow = new ShadowComponent( game, this );
|
||||||
SetModel( "humanoid" );
|
SetModel( "humanoid" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +40,6 @@ namespace ClassicalSharp {
|
|||||||
public override void Despawn() {
|
public override void Despawn() {
|
||||||
game.Graphics.DeleteTexture( ref PlayerTextureId );
|
game.Graphics.DeleteTexture( ref PlayerTextureId );
|
||||||
game.Graphics.DeleteTexture( ref nameTex.ID );
|
game.Graphics.DeleteTexture( ref nameTex.ID );
|
||||||
if( shadowTex != -1 )
|
|
||||||
game.Graphics.DeleteTexture( ref shadowTex );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void InitRenderingData() {
|
protected void InitRenderingData() {
|
||||||
|
@ -162,6 +162,10 @@ namespace ClassicalSharp {
|
|||||||
info.InitLightOffsets();
|
info.InitLightOffsets();
|
||||||
game.Events.RaiseBlockDefinitionChanged();
|
game.Events.RaiseBlockDefinitionChanged();
|
||||||
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
|
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;
|
string path = dx ? build.DirectXPath : build.OpenGLPath;
|
||||||
Utils.LogDebug( "Updating to: " + path );
|
Utils.LogDebug( "Updating to: " + path );
|
||||||
|
Patcher.PatchTime = build.TimeBuilt;
|
||||||
Patcher.Update( path );
|
Patcher.Update( path );
|
||||||
game.ShouldExit = true;
|
game.ShouldExit = true;
|
||||||
game.ShouldUpdate = true;
|
game.ShouldUpdate = true;
|
||||||
|
@ -4,12 +4,15 @@ using System.IO;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using ClassicalSharp;
|
||||||
using ClassicalSharp.TexturePack;
|
using ClassicalSharp.TexturePack;
|
||||||
|
|
||||||
namespace Launcher.Updater {
|
namespace Launcher.Updater {
|
||||||
|
|
||||||
public static class Patcher {
|
public static class Patcher {
|
||||||
|
|
||||||
|
public static DateTime PatchTime;
|
||||||
|
|
||||||
public static void Update( string dir ) {
|
public static void Update( string dir ) {
|
||||||
using( WebClient client = new WebClient() ) {
|
using( WebClient client = new WebClient() ) {
|
||||||
byte[] zipData = client.DownloadData( UpdateCheckTask.UpdatesUri + dir );
|
byte[] zipData = client.DownloadData( UpdateCheckTask.UpdatesUri + dir );
|
||||||
@ -25,9 +28,9 @@ namespace Launcher.Updater {
|
|||||||
info = new ProcessStartInfo( "cmd.exe", "/c update.bat" );
|
info = new ProcessStartInfo( "cmd.exe", "/c update.bat" );
|
||||||
} else {
|
} else {
|
||||||
string path = Path.Combine( Program.AppDirectory, "update.sh" );
|
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
|
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 )
|
if( code != 0 )
|
||||||
throw new InvalidOperationException( "chmod returned : " + code );
|
throw new InvalidOperationException( "chmod returned : " + code );
|
||||||
info = new ProcessStartInfo( "xterm", '"' + path + '"');
|
info = new ProcessStartInfo( "xterm", '"' + path + '"');
|
||||||
@ -50,11 +53,19 @@ namespace Launcher.Updater {
|
|||||||
reader.Extract( stream );
|
reader.Extract( stream );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
static void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
||||||
string path = Path.Combine( Program.AppDirectory, "CS_Update" );
|
string path = Path.Combine( Program.AppDirectory, "CS_Update" );
|
||||||
path = Path.Combine( path, Path.GetFileName( filename ) );
|
path = Path.Combine( path, Path.GetFileName( filename ) );
|
||||||
File.WriteAllBytes( path, data );
|
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