Skip to content

Commit

Permalink
Change AbilityHelper.spawnEntityAtPlayer to automatically put items i…
Browse files Browse the repository at this point in the history
…nto inventories by default (prevents lag-dupe) and also play sound if it got picked up.
  • Loading branch information
bonii-xx committed Nov 25, 2014
1 parent 6d677dc commit aa32879
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/tconstruct/library/tools/AbilityHelper.java
Expand Up @@ -21,6 +21,7 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import tconstruct.TConstruct;
import tconstruct.library.*;
import tconstruct.library.util.PiercingEntityDamage;

Expand Down Expand Up @@ -568,10 +569,18 @@ public static void spawnItemAtPlayer (EntityPlayer player, ItemStack stack)
{
if (!player.worldObj.isRemote)
{
EntityItem entityitem = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, stack);
player.worldObj.spawnEntityInWorld(entityitem);
if (!(player instanceof FakePlayer))
entityitem.onCollideWithPlayer(player);
// try to put it into the players inventory
if(player instanceof FakePlayer || !player.inventory.addItemStackToInventory(stack)) // note that the addItemStackToInventory is not called for fake players
{
// drop the rest as an entity
EntityItem entityitem = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, stack);
player.worldObj.spawnEntityInWorld(entityitem);
if (!(player instanceof FakePlayer))
entityitem.onCollideWithPlayer(player);
}
// if it got picked up, we're playing the sound
else
player.worldObj.playSoundAtEntity(player, "random.pop", 0.2F, ((TConstruct.random.nextFloat() - TConstruct.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}

}
Expand Down

0 comments on commit aa32879

Please sign in to comment.