fix inventory switching sounds when using a placer or the drill

This commit is contained in:
Ellpeck 2017-02-06 14:01:11 +01:00
parent df81083ca7
commit c98b5cf85f
2 changed files with 14 additions and 5 deletions

View file

@ -106,14 +106,14 @@ public class ItemDrill extends ItemEnergy{
if(StackUtil.isValid(equip) && equip != stack){ if(StackUtil.isValid(equip) && equip != stack){
ItemStack toPlaceStack = equip.copy(); ItemStack toPlaceStack = equip.copy();
player.setHeldItem(hand, toPlaceStack); WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack);
//tryPlaceItemIntoWorld could throw an Exception //tryPlaceItemIntoWorld could throw an Exception
try{ try{
//Places the Block into the World //Places the Block into the World
if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){ if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
if(!player.capabilities.isCreativeMode){ if(!player.capabilities.isCreativeMode){
player.setHeldItem(hand, StackUtil.validateCopy(toPlaceStack)); WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, StackUtil.validateCopy(toPlaceStack));
} }
} }
} }
@ -123,7 +123,7 @@ public class ItemDrill extends ItemEnergy{
} }
player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand)); player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand));
player.setHeldItem(hand, stack); WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, stack);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }

View file

@ -242,12 +242,12 @@ public final class WorldUtil{
if(world instanceof WorldServer){ if(world instanceof WorldServer){
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer)world); FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer)world);
ItemStack heldBefore = fake.getHeldItemMainhand(); ItemStack heldBefore = fake.getHeldItemMainhand();
fake.setHeldItem(EnumHand.MAIN_HAND, stack.copy()); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, stack.copy());
fake.getHeldItemMainhand().onItemUse(fake, world, offsetPos, fake.getActiveHand(), side.getOpposite(), 0.5F, 0.5F, 0.5F); fake.getHeldItemMainhand().onItemUse(fake, world, offsetPos, fake.getActiveHand(), side.getOpposite(), 0.5F, 0.5F, 0.5F);
ItemStack result = fake.getHeldItem(EnumHand.MAIN_HAND); ItemStack result = fake.getHeldItem(EnumHand.MAIN_HAND);
fake.setHeldItem(EnumHand.MAIN_HAND, heldBefore); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, heldBefore);
return result; return result;
} }
} }
@ -469,4 +469,13 @@ public final class WorldUtil{
} }
return 0F; return 0F;
} }
public static void setHandItemWithoutAnnoyingSound(EntityPlayer player, EnumHand hand, ItemStack stack){
if(hand == EnumHand.MAIN_HAND){
player.inventory.mainInventory.set(player.inventory.currentItem, stack);
}
else if(hand == EnumHand.OFF_HAND){
player.inventory.offHandInventory.set(0, stack);
}
}
} }