Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiclasOlofsson/2a7933146f0e29474f87683b32c62847 to your computer and use it in GitHub Desktop.
Save NiclasOlofsson/2a7933146f0e29474f87683b32c62847 to your computer and use it in GitHub Desktop.
Elytra extreme Player.OnTick code
public override void OnTick()
{
HungerManager.OnTick();
base.OnTick();
if (IsGliding)
{
if (CurrentSpeed > 30)
{
var particle = new CriticalParticle(Level);
particle.Position = KnownPosition.ToVector3();
particle.Spawn();
}
if (Level.TickTime % 10 == 0)
{
AddPopup(new Popup()
{
Id = 10,
MessageType = MessageType.Tip,
Message = $"Speed: {CurrentSpeed:F2}m/s",
Duration = 20 * 5,
});
}
if (CurrentSpeed > 20 && Username.StartsWith("gurun"))
{
ThreadPool.QueueUserWorkItem(state =>
{
if (!IsGliding) return;
{
int radius = 3;
int speedAjustment = (int) Math.Ceiling(CurrentSpeed/radius);
List<FallingBlock> thrownBlocks = new List<FallingBlock>();
for (int i = 0; i < speedAjustment; i++)
{
if(!IsGliding) return;
var direction = Vector3.Normalize(KnownPosition.GetDirection());
BlockCoordinates exploadPoint = KnownPosition.ToVector3() + direction*(float) (CurrentSpeed/speedAjustment*i + 1);
var offset = new BlockCoordinates(0, 1, 0);
if (i == 1&& !Level.IsAir(exploadPoint + new BlockCoordinates(0, -radius, 0)))
{
Block block = new Glowstone() {Coordinates = exploadPoint + new BlockCoordinates(0, -radius, 0)};
Level.SetBlock(block);
}
if (i == 2 && !Level.IsAir(exploadPoint + new BlockCoordinates(0, radius + 2, 0)))
{
Block block = new Glowstone() {Coordinates = exploadPoint + new BlockCoordinates(0, radius + 2, 0)};
Level.SetBlock(block);
}
bool allAirOver = true;
for (int x = -10; x < 11; x++)
{
for (int y = 10; y >= 2; y--)
{
for (int z = -10; z < 11; z++)
{
var coordinates = exploadPoint + new BlockCoordinates(x, y, z);
if (coordinates.DistanceTo(exploadPoint) > radius) continue;
if (!Level.IsAir(coordinates + offset))
{
allAirOver = false;
Level.SetAir(coordinates + offset);
}
else
{
//var particle = new CriticalParticle(Level);
//particle.Position = exploadPoint + new BlockCoordinates(x, y, z);
//particle.Spawn();
}
}
}
}
//if (!allAirOver)
{
for (int x = -10; x < 11; x++)
{
for (int y = 1; y >= -10; y--)
{
for (int z = -10; z < 11; z++)
{
var coordinates = exploadPoint + new BlockCoordinates(x, y, z);
if (coordinates.DistanceTo(exploadPoint) > radius) continue;
if (!Level.IsAir(coordinates + offset))
{
if (allAirOver/* && i == speedAjustment -1*/)
{
Block block = Level.GetBlock(coordinates + offset);
//Block block = new EmeraldBlock() {Coordinates = coordinates + offset};
var bbox = block.GetBoundingBox();
var d = (bbox.Max - bbox.Min) / 2;
Vector3 pos = coordinates + offset;
pos += new Vector3(d.X, 0.1f, d.Z);
thrownBlocks.Add(new FallingBlock(Level, block)
{
KnownPosition = new PlayerLocation(pos),
Velocity = new Vector3(0, 0.6f, 0)
});
//var drops = block.GetDrops(null);
//if(drops != null)
//{
// foreach (var drop in drops)
// {
// var dropItem = new ItemEntity(Level, drop);
// dropItem.KnownPosition = new PlayerLocation(pos);
// dropItem.Velocity = Velocity + new Vector3(0, 1.8f, 0);
// dropItem.SpawnEntity();
// }
//}
}
Level.SetAir(coordinates + offset);
}
else
{
//var particle = new CriticalParticle(Level);
//particle.Position = exploadPoint + new BlockCoordinates(x, y, z);
//particle.Spawn();
}
}
}
}
}
}
Thread.Sleep(1000);
thrownBlocks.Reverse();
foreach (var thrownBlock in thrownBlocks)
{
thrownBlock.SpawnEntity();
}
}
});
}
}
foreach (var effect in Effects)
{
effect.Value.OnTick(this);
}
//if (Level.TickTime%30 == 0)
//{
// if (Username.Equals("gurun"))
// {
// Popup popup = new Popup
// {
// Duration = 1,
// MessageType = MessageType.Tip,
// Message = string.Format("TT: {0}ms AvgTT: {1}ms", Level.LastTickProcessingTime, Level.AvarageTickProcessingTime)
// };
// AddPopup(popup);
// }
//}
bool hasDisplayedPopup = false;
bool hasDisplayedTip = false;
lock (Popups)
{
// Code below is just pure magic and mystery. In short, it takes care of sorting a list of popups
// based on priority, ticks and delays. And then makes sure that the most applicable popup and tip
// is presented.
// In the end it adjusts for the display times for tip (20ticks) and popup (10ticks) and sends it at
// regular intervalls to make sure there is no blinking.
foreach (var popup in Popups.OrderByDescending(p => p.Priority).ThenByDescending(p => p.CurrentTick))
{
if (popup.CurrentTick >= popup.Duration + popup.DisplayDelay)
{
Popups.Remove(popup);
continue;
}
if (popup.CurrentTick >= popup.DisplayDelay)
{
// Tip is ontop
if (popup.MessageType == MessageType.Tip && !hasDisplayedTip)
{
if (popup.CurrentTick <= popup.Duration + popup.DisplayDelay - 30)
if (popup.CurrentTick%20 == 0 || popup.CurrentTick == popup.Duration + popup.DisplayDelay - 30) SendMessage(popup.Message, type: popup.MessageType);
hasDisplayedTip = true;
}
// Popup is below
if (popup.MessageType == MessageType.Popup && !hasDisplayedPopup)
{
if (popup.CurrentTick <= popup.Duration + popup.DisplayDelay - 30)
if (popup.CurrentTick%20 == 0 || popup.CurrentTick == popup.Duration + popup.DisplayDelay - 30) SendMessage(popup.Message, type: popup.MessageType);
hasDisplayedPopup = true;
}
}
popup.CurrentTick++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment