Play sound on placing blocks.

This commit is contained in:
James McKay committed 2015-10-08 09:30:58 +11:00
1 parent 138d08252c
commit 9b720ff498
8 files changed
+32 -4

No files matched your search

@@ -33,7 +33,7 @@ public class BlockEvents {
&& event.target != null && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
IPlayerShim playerShim = new BasicPlayerShim(event.player);
if(event.player.capabilities.isCreativeMode) {
playerShim = new CreativePlayerShim();
playerShim = new CreativePlayerShim(event.player);
}
IWorldShim worldShim = new BasicWorldShim(event.player.getEntityWorld());
UnbreakingWand unbreakingWand = new UnbreakingWand(event.currentItem);
@@ -112,6 +112,7 @@ public class WandWorker {
boolean blockPlaceSuccess = world.copyBlock(originalBlock, blockPos);
if(blockPlaceSuccess) {
world.playPlaceAtBlock(blockPos, world.getBlock(originalBlock));
boolean takeFromInventory = player.useItem(getEquivalentItemStack(originalBlock));
if(!takeFromInventory) {
world.setBlockToAir(blockPos);
@@ -10,6 +10,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import portablejim.bbw.basics.EnumLock;
import portablejim.bbw.basics.Point3d;
import portablejim.bbw.core.WandWorker;
import portablejim.bbw.core.wands.UnbreakingWand;
@@ -37,7 +38,7 @@ public class ItemUnbreakableWand extends Item implements IWandItem{
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
IPlayerShim playerShim = new BasicPlayerShim(player);
if(player.capabilities.isCreativeMode) {
playerShim = new CreativePlayerShim();
playerShim = new CreativePlayerShim(player);
}
IWorldShim worldShim = new BasicWorldShim(world);
UnbreakingWand unbreakingWand = new UnbreakingWand(itemstack);
@@ -50,7 +51,7 @@ public class ItemUnbreakableWand extends Item implements IWandItem{
int numBlocks = Math.min(unbreakingWand.getMaxBlocks(), playerShim.countItems(targetItemstack));
FMLLog.info("Max blocks: %d (%d|%d", numBlocks, unbreakingWand.getMaxBlocks(), playerShim.countItems(targetItemstack));
LinkedList<Point3d> blocks = worker.getBlockPositionList(clickedPos, ForgeDirection.getOrientation(side), numBlocks);
LinkedList<Point3d> blocks = worker.getBlockPositionList(clickedPos, ForgeDirection.getOrientation(side), numBlocks, EnumLock.NOLOCK);
worker.placeBlocks(blocks, clickedPos);
@@ -1,7 +1,10 @@
package portablejim.bbw.shims;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import portablejim.bbw.basics.Point3d;
/**
* Wrap a player to provide basic functions.
@@ -49,4 +52,9 @@ public class BasicPlayerShim implements IPlayerShim {
}
return false;
}
@Override
public Point3d getPlayerPosition() {
return new Point3d((int)player.posX, (int)player.posY, (int)player.posZ);
}
}
@@ -64,4 +64,11 @@ public class BasicWorldShim implements IWorldShim {
List entitiesWithinAABB = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
return entitiesWithinAABB.size() > 0;
}
@Override
public void playPlaceAtBlock(Point3d position, Block blockType) {
if(position != null && blockType != null) {
world.playSoundEffect(position.x + 0.5D, position.y + 0.5D, position.z + 0.5D, blockType.stepSound.func_150496_b(), (blockType.stepSound.getVolume() + 1.0F) / 2.0F, blockType.stepSound.getPitch() * 0.8F);
}
}
}
@@ -1,11 +1,18 @@
package portablejim.bbw.shims;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import portablejim.bbw.basics.Point3d;
/**
* Wrap functions for a creative player.
*/
public class CreativePlayerShim implements IPlayerShim {
public class CreativePlayerShim extends BasicPlayerShim implements IPlayerShim {
public CreativePlayerShim(EntityPlayer player) {
super(player);
}
@Override
public int countItems(ItemStack itemStack) {
return Integer.MAX_VALUE;
@@ -1,6 +1,7 @@
package portablejim.bbw.shims;
import net.minecraft.item.ItemStack;
import portablejim.bbw.basics.Point3d;
/**
* Wrap player functions.
@@ -8,4 +9,5 @@ import net.minecraft.item.ItemStack;
public interface IPlayerShim {
int countItems(ItemStack itemStack);
boolean useItem(ItemStack itemStack);
Point3d getPlayerPosition();
}
@@ -21,4 +21,6 @@ public interface IWorldShim {
int getMetadata(Point3d blockPos);
boolean entitiesInBox(AxisAlignedBB box);
void playPlaceAtBlock(Point3d position, Block blockType);
}