Update ItemHandlerHelper.giveItemToPlayer to allow player who picked up the item to hear the sound as well (#4720)

This commit is contained in:
Parker Young 2018-04-01 03:43:39 -04:00 committed by LexManos
parent 6f642ba6ce
commit db3b2549e2
2 changed files with 42 additions and 1 deletions

View file

@ -181,7 +181,7 @@ public class ItemHandlerHelper
// play sound if something got picked up
if (remainder.isEmpty() || remainder.getCount() != stack.getCount())
{
world.playSound(player, player.posX, player.posY, player.posZ,
world.playSound(null, player.posX, player.posY + 0.5, player.posZ,
SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
}

View file

@ -0,0 +1,41 @@
package net.minecraftforge.debug;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.items.ItemHandlerHelper;
/**
* A mod to test that ItemHandlerHelper.giveItemToPlayer works.
* More specifically, that all players, including the one receiving the item, can hear the pickup sound when it happens.
* This mod makes it so when you right click the air with a piece of dirt in your hand, you get another piece of dirt.
* It's not a dupe glitch...it's a dupe "feature"...
*/
@Mod(modid = "giveitemtoplayertest", name = "ItemHandlerHelper.giveItemToPlayer Test", version = "1.0")
public class GiveItemToPlayerTest {
private static final boolean ENABLED = false;
@GameRegistry.ItemStackHolder("minecraft:dirt")
public static final ItemStack dirt = null;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
if (ENABLED) {
MinecraftForge.EVENT_BUS.register(this);
}
}
@SubscribeEvent
public void rightClick(PlayerInteractEvent.RightClickItem event) {
if (!event.getWorld().isRemote && event.getItemStack().isItemEqual(dirt)) {
ItemHandlerHelper.giveItemToPlayer(event.getEntityPlayer(), dirt);
}
event.setCanceled(true);
event.setCancellationResult(EnumActionResult.SUCCESS);
}
}