/** * Override sounds when walking on block. * * @param event */ @SideOnly(Side.CLIENT) @SubscribeEvent public void onPlaySoundAtEntityEvent(PlaySoundAtEntityEvent event) { if (event != null && event.name != null && event.name.contains(CarpentersBlocks.MODID)) { Entity entity = event.entity; /* * The function to my knowledge is only used for playing walking sounds * at entity, so we'll check for the conditions first. */ if (!isMovingOnGround(entity)) { return; } TEBase TE = getTileEntityAtFeet(entity); if (TE != null) { // Give SoundType a valid resource by default event.name = Blocks.planks.stepSound.getStepResourcePath(); // Gather accurate SoundType based on block properties Block block = BlockProperties.toBlock(getSurfaceItemStack(TE)); if (!(block instanceof BlockCoverable)) { event.name = block.stepSound.getStepResourcePath(); } } } }
@SubscribeEvent public void onLivingUpdateEvent(LivingUpdateEvent event) { Entity entity = event.entityLiving; World world = entity.worldObj; /* * The purpose of the function is to manifest sprint particles * and adjust slipperiness when entity is moving on block, so check * that the conditions are met first. */ if (!isMovingOnGround(entity)) { return; } TEBase TE = getTileEntityAtFeet(entity); if (TE != null) { ItemStack itemStack = getSurfaceItemStack(TE); /* Spawn sprint particles client-side. */ if (world.isRemote && entity.isSprinting() && !entity.isInWater()) { ParticleHelper.spawnTileParticleAt(entity, itemStack); } /* Adjust block slipperiness according to cover. */ Block block = BlockProperties.toBlock(itemStack); if (block instanceof BlockCoverable) { TE.getBlockType().slipperiness = Blocks.dirt.slipperiness; } else { TE.getBlockType().slipperiness = block.slipperiness; } } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onPlaySoundEvent(PlaySoundEvent17 event) { if (event != null && event.name != null && event.name.contains(CarpentersBlocks.MODID)) { if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { World world = FMLClientHandler.instance().getClient().theWorld; int x = MathHelper.floor_double(event.sound.getXPosF()); int y = MathHelper.floor_double(event.sound.getYPosF()); int z = MathHelper.floor_double(event.sound.getZPosF()); // We'll set a default block type to be safe Block block = Blocks.planks; // Grab approximate origin, and gather accurate block type TEBase TE = getApproximateSoundOrigin(world, x, y, z); if (TE != null && TE.hasAttribute(TE.ATTR_COVER[6])) { block = BlockProperties.toBlock(BlockProperties.getCoverSafe(TE, 6)); } if (event.name.startsWith("step.")) { event.result = new PositionedSoundRecord( new ResourceLocation(block.stepSound.getStepResourcePath()), block.stepSound.getVolume() * 0.15F, block.stepSound.getPitch(), x + 0.5F, y + 0.5F, z + 0.5F); } else { // "dig." usually event.result = new PositionedSoundRecord( new ResourceLocation(block.stepSound.getBreakSound()), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F, x + 0.5F, y + 0.5F, z + 0.5F); } } } }
@SideOnly(Side.CLIENT) @SubscribeEvent /** Grabs mouse scroll events for slope selection. */ public void onMouseEvent(MouseEvent event) { // We only want to process wheel events if (event.button < 0) { EntityPlayer entityPlayer = Minecraft.getMinecraft().thePlayer; if (entityPlayer != null && entityPlayer.isSneaking()) { ItemStack itemStack = entityPlayer.getHeldItem(); if (itemStack != null && itemStack.getItem() instanceof ItemBlock && BlockProperties.toBlock(itemStack).equals(BlockRegistry.blockCarpentersSlope)) { if (event.dwheel != 0) { PacketHandler.sendPacketToServer( new PacketSlopeSelect(entityPlayer.inventory.currentItem, event.dwheel > 0)); } event.setCanceled(true); } } } }