Skip to content

Instantly share code, notes, and snippets.

@steviegt6
Created December 24, 2024 05:30
Show Gist options
  • Select an option

  • Save steviegt6/da7479afa2ee6809b57d2b5dc0a28805 to your computer and use it in GitHub Desktop.

Select an option

Save steviegt6/da7479afa2ee6809b57d2b5dc0a28805 to your computer and use it in GitHub Desktop.
public static Rectangle GetDrawHitbox(int type, Player user)
{
if (Main.dedServ)
{
return Rectangle.Empty;
}
Main.instance.LoadItem(type);
if (ItemID.Sets.IsFood[type])
{
return TextureAssets.Item[type].Frame(1, 3, 0, 1);
}
switch (type)
{
case 75:
return TextureAssets.Item[type].Frame(1, 8);
case 520:
case 521:
case 547:
case 548:
case 549:
case 575:
case 3453:
case 3454:
case 3455:
case 3580:
case 3581:
case 4068:
case 4069:
case 4070:
return TextureAssets.Item[type].Frame(1, 4);
default:
return TextureAssets.Item[type].Frame();
}
}
private void ItemCheck_GetMeleeHitbox(Item sItem, Rectangle heldItemFrame, out bool dontAttack, out Rectangle itemRectangle)
{
dontAttack = false;
itemRectangle = new Rectangle((int)itemLocation.X, (int)itemLocation.Y, 32, 32);
if (!Main.dedServ)
{
int num = heldItemFrame.Width;
int num2 = heldItemFrame.Height;
switch (sItem.type)
{
case 5094:
num -= 10;
num2 -= 10;
break;
case 5095:
num -= 10;
num2 -= 10;
break;
case 5096:
num -= 12;
num2 -= 12;
break;
case 5097:
num -= 8;
num2 -= 8;
break;
}
itemRectangle = new Rectangle((int)itemLocation.X, (int)itemLocation.Y, num, num2);
}
float adjustedItemScale = GetAdjustedItemScale(sItem);
itemRectangle.Width = (int)((float)itemRectangle.Width * adjustedItemScale);
itemRectangle.Height = (int)((float)itemRectangle.Height * adjustedItemScale);
if (direction == -1)
{
itemRectangle.X -= itemRectangle.Width;
}
if (gravDir == 1f)
{
itemRectangle.Y -= itemRectangle.Height;
}
if (sItem.useStyle == 1)
{
if ((double)itemAnimation < (double)itemAnimationMax * 0.333)
{
if (direction == -1)
{
itemRectangle.X -= (int)((double)itemRectangle.Width * 1.4 - (double)itemRectangle.Width);
}
itemRectangle.Width = (int)((double)itemRectangle.Width * 1.4);
itemRectangle.Y += (int)((double)itemRectangle.Height * 0.5 * (double)gravDir);
itemRectangle.Height = (int)((double)itemRectangle.Height * 1.1);
}
else if (!((double)itemAnimation < (double)itemAnimationMax * 0.666))
{
if (direction == 1)
{
itemRectangle.X -= (int)((double)itemRectangle.Width * 1.2);
}
itemRectangle.Width *= 2;
itemRectangle.Y -= (int)(((double)itemRectangle.Height * 1.4 - (double)itemRectangle.Height) * (double)gravDir);
itemRectangle.Height = (int)((double)itemRectangle.Height * 1.4);
}
}
else if (sItem.useStyle == 3)
{
if ((double)itemAnimation > (double)itemAnimationMax * 0.666)
{
dontAttack = true;
}
else
{
if (direction == -1)
{
itemRectangle.X -= (int)((double)itemRectangle.Width * 1.4 - (double)itemRectangle.Width);
}
itemRectangle.Width = (int)((double)itemRectangle.Width * 1.4);
itemRectangle.Y += (int)((double)itemRectangle.Height * 0.6);
itemRectangle.Height = (int)((double)itemRectangle.Height * 0.6);
if (sItem.type == 946 || sItem.type == 4707)
{
itemRectangle.Height += 14;
itemRectangle.Width -= 10;
if (direction == -1)
{
itemRectangle.X += 10;
}
}
}
}
if (sItem.type == 1450 && Main.rand.Next(3) == 0)
{
int num3 = -1;
float x = itemRectangle.X + Main.rand.Next(itemRectangle.Width);
float y = itemRectangle.Y + Main.rand.Next(itemRectangle.Height);
if (Main.rand.Next(500) == 0)
{
num3 = Gore.NewGore(new Vector2(x, y), default(Vector2), 415, (float)Main.rand.Next(51, 101) * 0.01f);
}
else if (Main.rand.Next(250) == 0)
{
num3 = Gore.NewGore(new Vector2(x, y), default(Vector2), 414, (float)Main.rand.Next(51, 101) * 0.01f);
}
else if (Main.rand.Next(80) == 0)
{
num3 = Gore.NewGore(new Vector2(x, y), default(Vector2), 413, (float)Main.rand.Next(51, 101) * 0.01f);
}
else if (Main.rand.Next(10) == 0)
{
num3 = Gore.NewGore(new Vector2(x, y), default(Vector2), 412, (float)Main.rand.Next(51, 101) * 0.01f);
}
else if (Main.rand.Next(3) == 0)
{
num3 = Gore.NewGore(new Vector2(x, y), default(Vector2), 411, (float)Main.rand.Next(51, 101) * 0.01f);
}
if (num3 >= 0)
{
Main.gore[num3].velocity.X += direction * 2;
Main.gore[num3].velocity.Y *= 0.3f;
}
}
if (sItem.type == 3542)
{
dontAttack = true;
}
if (sItem.type == 3779)
{
dontAttack = true;
Vector2 vector = itemLocation + new Vector2(direction * 30, -8f);
Vector2 vector2 = vector - position;
for (float num4 = 0f; num4 < 1f; num4 += 0.2f)
{
Vector2 vector3 = Vector2.Lerp(oldPosition + vector2 + new Vector2(0f, gfxOffY), vector, num4);
Dust obj = Main.dust[Dust.NewDust(vector - Vector2.One * 8f, 16, 16, 27, 0f, -2f)];
obj.noGravity = true;
obj.position = vector3;
obj.velocity = new Vector2(0f, (0f - gravDir) * 2f);
obj.scale = 1.2f;
obj.alpha = 200;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment