Can you help me find out why this sprite glitches?

For some reason whenever I use this slime sprite it cuts in half. Here is the code:

using Terraria.ID;
using Terraria.ModLoader;
using Terraria;

namespace Upgrade_weapons.Items
{
public class copperslime : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Copper Slime");
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.BlueSlime];
}
public override void SetDefaults()
{
npc.width = 32;
npc.height = 22;
npc.HitSound = SoundID.NPCHit1;
npc.damage = 3;
npc.defense = 15;
npc.DeathSound = SoundID.NPCDeath1;
npc.value = 500f;
npc.knockBackResist = 0.9f;
npc.lifeMax = 40;
npc.aiStyle = 1;
aiType = NPCID.BlueSlime;
banner = Item.NPCtoBanner(NPCID.Zombie);
bannerItem = Item.BannerToItem(banner);
npc.alpha = 175;

}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{

return 0.2f;

float chance = 0.2f;
if (!Main.dayTime)
{

chance += .2f;
if (spawnInfo.spawnTileY <= Main.rockLayer && spawnInfo.spawnTileY >= Main.worldSurface * 15)
{
chance += .3f;
}

}

}
public override void NPCLoot()
{
if (Main.rand.Next(1) == 0)
{
Item.NewItem(npc.position, ItemID.CopperOre, 9);


}
if(Main.hardMode)
{
Item.NewItem(npc.position, ItemID.CopperBar, 5);
}





}



}


}


I will attach the sprite.
The screenshot is blurry but it cuts the bottom half of this sprite.

My mod is called Upgraded weapons.
Thank you for taking the time to look at this post!
 

Attachments

  • copperslime.png
    copperslime.png
    3.1 KB · Views: 75
Is the sprite you posted the entire sprite? Because you are using Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.BlueSlime]; and the Blue Slime enemy has 2 animation frames, but you only have one.
 
Is the sprite you posted the entire sprite? Because you are using Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.BlueSlime]; and the Blue Slime enemy has 2 animation frames, but you only have one.
Thank you again. Though it isn't switching between the 2 frames. Do you have any idea why?
(Sorry for asking all these questions, this is my second mod and my first one was trash.)
 
Where you have aiType = NPCID.BlueSlime, below it add this line: animationType = NPCID.BlueSlime;
This enemy doesn't spawn. Can you help me please? Here is the code:
using Terraria.ID;
using Terraria.ModLoader;
using Terraria;

namespace Upgrade_weapons.Items.NPC
{
public class irradiatedslime : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Irradiated Slime");
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.BlueSlime];
}
public override void SetDefaults()
{

npc.width = 32;
npc.height = 22;
npc.HitSound = SoundID.NPCHit1;
npc.damage = 19;
npc.defense = 15;
npc.DeathSound = SoundID.NPCDeath1;
npc.value = 500f;
npc.knockBackResist = 0f;
npc.lifeMax = 500;
npc.aiStyle = 1;
aiType = NPCID.BlueSlime;
animationType = 5;
npc.alpha = 25;
if (Main.hardMode)
{

npc.lifeMax = 900;
npc.damage = 40;
npc.defense = 30;
}
}
public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit)
{
target.AddBuff(mod.BuffType("radiation"), 240);
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{

return 0.0f;
float chance = 0.0f;
if (spawnInfo.player.ZoneJungle)
{
return 10.1f;
if (Main.hardMode)
{

return 5.1f;

}
}
else
{
return 0f;
}
}
public override void NPCLoot()
{
if (Main.rand.Next(1) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 30);

}
if (Main.rand.Next(4) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 1);

}
if (Main.rand.Next(4) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 1);

}
if (Main.rand.Next(4) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 1);

}
if (Main.rand.Next(4) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 1);

}
if (Main.rand.Next(4) == 0)
{
Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 1);

}

if (Main.hardMode)
{



}





}



}


}
 
You have extra code in your SpawnChance() that is returning 0 always. Remove it like so:

Code:
public override float SpawnChance(NPCSpawnInfo spawnInfo) {
    if (spawnInfo.player.ZoneJungle)
    {
        return 10.1f;
        if (Main.hardMode)
        {
            return 5.1f;
        }
    }
    else
    {
        return 0f;
    }
}
 
You have extra code in your SpawnChance() that is returning 0 always. Remove it like so:

Code:
public override float SpawnChance(NPCSpawnInfo spawnInfo) {
    if (spawnInfo.player.ZoneJungle)
    {
        return 10.1f;
        if (Main.hardMode)
        {
            return 5.1f;
        }
    }
    else
    {
        return 0f;
    }
}
Thank you but I have another error. Irradiated gel doesn't want to drop even though I set it as a 1/1 chance. Can you help me why? The code is the same as above with the exception of the spawn rate being changed.
 
I think you should change this Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 30);
To this Item.NewItem(npc.getRect(), ModContent.ItemType<iraddiatedgel>());

Also FYI make sure 'irradiated' is spelled correctly. You should check out ExampleMod and other open source mods to see how other NPCs are coded.
 
I think you should change this Item.NewItem(npc.position, mod.ItemType("iraddiatedgel"), 30);
To this Item.NewItem(npc.getRect(), ModContent.ItemType<iraddiatedgel>());

Also FYI make sure 'irradiated' is spelled correctly. You should check out ExampleMod and other open source mods to see how other NPCs are coded.
By the way, this method doesn't work for me. Also I have a problem with a tile sprite. Here is the code for the tile:

using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria;
namespace Upgrade_weapons.Items.Craftingstations
{
public class enchantingstation : ModTile
{


public override void SetDefaults()
{

Main.tileLighted[Type] = true;
drop = mod.ItemType("enchantstation");
ModTranslation name = CreateMapEntryName();
name.SetDefault("Enchanting Station");
AddMapEntry(Color.Blue);

}


public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)
{


b = 1f;



}

}
}

This is the item code:

using Terraria.ID;
using Terraria.ModLoader;
using Terraria;
namespace Upgrade_weapons.Items.Craftingstations
{
public class enchantstation : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Enchanting Station");
Tooltip.SetDefault("Allows you to imbue your weapons to be more powerful.");
}

public override void SetDefaults()
{

item.autoReuse = true;

item.consumable = true;

item.useTime = 19;
item.useAnimation = 19;
item.useTurn = true;
item.useStyle = 1;
item.UseSound = SoundID.Item1;
item.createTile = mod.TileType("enchantingstation");

}




}
}

The sprite is attached. Thank you!
 

Attachments

  • enchantingstation.png
    enchantingstation.png
    2 KB · Views: 31
What is the issue you're having? What do you mean when you say the method doesn't work?

If you're having graphical issues with the tile, check out how an example tile is done - tModLoader/ExampleClock.png at master · tModLoader/tModLoader
Also I highly recommend asking on the Discord as well.
I want to add an item to the dryad but it is giving this error and I don't understand why.

Here is the code to add the item:


using TGTEM.Food;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;

namespace TGTEM.NPCShopEditor
{
class FoodNPCShop : GlobalNPC
{
public override void SetupShop(int type, Chest shop, ref int nextSlot) {

if (type == NPCID.Dryad) {

shop.item[nextSlot].SetDefaults(ModContent.ItemType<Wheat>());
nextSlot++; // Don't forget this line, it is essential.
}
}
}
}


Here is the code for the item I'm trying to add:



using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGTEM.Food.Sprites.Wheat
{
public class Wheat: ModItem
{
public override void SetDefaults()
{
item.width = 22;
item.height = 20;
item.value = Item.sellPrice(copper: 4);
item.rare = ItemRarityID.White;


}





}
}




This is the error:


Terraria.ModLoader.Exceptions.BuildException: Compiling TGTEM.XNA.dll failed with 1 errors and 0 warnings
Error: C:\Users\Documents\My Games\Terraria\ModLoader\Mod Sources\TGTEM\NPCShopEditor\NPCShopEditor.cs(15,56) : error CS0246: The type or namespace name 'Wheat' could not be found (are you missing a using directive or an assembly reference?)


Thank you for taking the time to look at this.
 
Because you have using TGTEM.Food; in GlobalNPC but the namespace of the actual item is namespace TGTEM.Food.Sprites.Wheat.

So just have: using TGTEM.Food.Sprites.Wheat;
 
Because you have using TGTEM.Food; in GlobalNPC but the namespace of the actual item is namespace TGTEM.Food.Sprites.Wheat.

So just have: using TGTEM.Food.Sprites.Wheat;
Thanks but know I'm trying to update it to 1.4 and I'm getting this error:


using TGTEM.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGTEM.Food.Sprites.Bread
{
public class Bread : ModItem
{
public override void SetDefaults()
{
item.width = 22;
item.height = 20;
item.value = Item.sellPrice(silver: 1);
item.rare = ItemRarityID.White;
item.useStyle = 2;
item.useAnimation = 10;
item.useTime = 10;
item.UseSound = SoundID.Item2;
item.maxStack = 999;
item.consumable = true;
}



public override bool UseItem(Player player)
{

player.AddBuff(BuffID.WellFed, 18750);
return base.UseItem(player);

}
public override void AddRecipes()
{
var recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "Flour", 3);


recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Error: C:/Users\Documents\My Games\Terraria\tModLoader\..\tModLoader\ModSources\TGTEM\Food\Fooditems\Bread.cs(26,24): error CS0508: 'Bread.UseItem(Player)': return type must be 'bool?' to match overridden member 'ModItem.UseItem(Player)'
 
In useitem, you have to return either true or false, it's a bool. So just use return true;
Sorry to bother you again but Im getting this error:




[19:04:11] [41/ERROR] [tML]: An error occurred while loading TGTEM
The mod(s) have been automatically disabled.
System.NullReferenceException: Object reference not set to an instance of an object.
at TGTEM.Food.Sprites.Bread.Bread.SetDefaults() in TGTEM\Food\Fooditems\Bread.cs:line 22
at Terraria.ModLoader.ItemLoader.SetDefaults(Item item, Boolean createModItem)
at Terraria.Item.SetDefaults(Int32 Type, Boolean noMatCheck)
at Terraria.Item.netDefaults(Int32 type)
at Terraria.UI.ItemSorting.SetupWhiteLists()
at Terraria.ModLoader.ModContent.Load(CancellationToken token)
at Terraria.ModLoader.ModLoader.Load(CancellationToken token)



From this code:




using TGTEM.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGTEM.Food.Sprites.Bread
{
public class Bread : ModItem
{
public override void SetDefaults()
{
item.width = 22;
item.height = 20;
item.value = Item.sellPrice(silver: 1);
item.rare = ItemRarityID.White;
item.useStyle = 2;
item.useAnimation = 10;
item.useTime = 10;
item.UseSound = SoundID.Item2;
item.maxStack = 999;
item.consumable = true;
DisplayName.SetDefault("Plain Bread");
Tooltip.SetDefault("Would go great with some hummus!");
}



public override bool UseItem(Player player)
{

player.AddBuff(BuffID.WellFed, 18750);
return base.UseItem(player);

}
public override void AddRecipes()
{
var recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "Flour", 3);


recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
DisplayName and Tooltip go in SetStaticDefaults. Are you using some type of old youtube or forum tutorial? Those are all massively out of date and will give you tons of errors.
 
Back
Top Bottom